Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Question

 
Piyush Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    Piyush Jain
    Ranch Hand
    Posts: 60
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Marc.

    I will send an email to them stating everything I remember about the question.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic