| Author |
Exception Question
|
Piyush Jain
Ranch Hand
Joined: Apr 25, 2003
Posts: 60
|
|
I took SCJP on saturday. I posted this question on certfication results forum, but nobody seems to answer it there, so I am posting it here. the questions were all ok, except one that i could not think an answer for. I don't remember it completely, but there was a statement between the try and catch, and should be giving a compiler error. However, the question was a short answer one and value of a string variable was asked. it looked somethng like this: public class Class { String counter = ""; void foo(int i){ try { if(i==0) throw new Exception(); } counter += "1"; catch { //some code } finally { //some code } } public static void main(String [] args) { foo(1); foo(0); //***** } } what is the value of variable counter at //***** according to me, the code should not compile since there is a statement between the try/catch. any comments? if it really can't compile, how should i go forward telling SUN this thing? they should not be penalizing me for this question in that case.
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
If you're in the US, try this link: http://suned.sun.com/US/contact_us/index.html Otherwise, select country from this page: http://suned.sun.com/ According to my testing, a statement between a try{} block and its associated catch(){} block will result in 2 compile-time errors: 'try' without 'catch' or 'finally''catch' without 'try' You'll want to provide Sun with as much specific information as you can, but I also think it's important to isolate the problem in general terms like this... [ September 14, 2004: Message edited by: marc weber ]
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Piyush Jain
Ranch Hand
Joined: Apr 25, 2003
Posts: 60
|
|
Thanks Marc. I will send an email to them stating everything I remember about the question.
|
 |
 |
|
|
subject: Exception Question
|
|
|