jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Question" Watch "Exception Question" New topic

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){
throw new Exception();

counter += "1";
//some code
//some code
public static void main(String [] args)
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

Joined: Aug 31, 2004
Posts: 11343

If you're in the US, try this link:


Otherwise, select country from this page:


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
    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.
    I agree. Here's the link: http://aspose.com/file-tools
    subject: Exception Question
    Similar Threads
    A Question for the group
    Passed SCJP 1.4/Help With Question on Exam
    a thread code
    Which executes first? ++ Operator Question.