*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes another question from MindQ Mock Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "another question from MindQ Mock Exam " Watch "another question from MindQ Mock Exam " New topic
Author

another question from MindQ Mock Exam

Ray Chang
Greenhorn

Joined: Sep 10, 2002
Posts: 25
31. Consider the code below:
void myMethod()
{ try
{
fragile();
}
catch( NullPointerException npex )
{
System.out.println( "NullPointerException thrown " );
}
catch( Exception ex )
{
System.out.println( "Exception thrown " );
}
finally
{
System.out.println( "Done with exceptions " );
}
System.out.println( "myMethod is done" );
}
What is printed to standard output if fragile() throws an IllegalArgumentException?
a) "NullPointerException thrown"
b) "Exception thrown"
c) "Done with exceptions"
d) "myMethod is done"
e) Nothing is printed
Is this question, I thought the exception throwed by fragile() was catched by the 2nd catch statement and then the finally statement executed.And then it jumps out of myMethod()
So my answer was b & c.
But the answer in the correct answer was b & c & d. What'd the problem?
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
After a catch block has been executed, control is always transferred to the finally block, if one is specified... On exit from a finally block, normal execution will resume. (Mughal p.158-159)
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
If you want it to jump out then you either use a return statement or don't catch the exception and declare a throws in your method definistion.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
 
subject: another question from MindQ Mock Exam
 
Similar Threads
From mIND q TEST some ques
Exception
Exceptions
MindQ Q31
Question related to exception