• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception Question

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Marc.

    I will send an email to them stating everything I remember about the question.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic