We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Try-Catch with Semantic Errors
Page Index Toggle Pages: 1
Try-Catch with Semantic Errors (Read 856 times)
Try-Catch with Semantic Errors
Oct 29th, 2007, 1:20am
 
I can't get a try/catch to work with a statement that gives me a semantic error. Below is a simplified bit of code that exemplifies my issue.

int[] array;
try {
 array = append(array, 2);
}
catch (Throwable t) {
 println("If you read this, the try-catch works");
}


I know there are better ways to accomplish the task of this example, but I'd like to use this form for a more complicated task. Any help in getting it to work would be appreciated. Thank you!
Re: Try-Catch with Semantic Errors
Reply #1 - Oct 29th, 2007, 1:43am
 
Hi,
you need to initialize your array before appending something to it.

try this
--------------------------------------------------------
int[] array = new int[0]; //initialize

try {
 array = append(array, 2);
}
catch (Throwable t) {
 println("If you read this, the try-catch works");
}
println(array);
-------------------------------------------------------
Cheers!
Re: Try-Catch with Semantic Errors
Reply #2 - Oct 29th, 2007, 3:59am
 
Even better than answering the question I asked! Thank you!!!
Page Index Toggle Pages: 1