File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions 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 "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

Tina Ang
Ranch Hand

Joined: Mar 12, 2002
Posts: 58
MindQ's question # 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
MindQ's answer is B,C,D. Why was D included?
Thanks!
Tina
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
try-catch block are for this only .
I mean ... not to terminate ur program when there is any exception, if there is any exception that is handled properly then NEXT statement after the try-catch block will be executed.
In ur case IllegalArgumentException is thrown and handled by Exception block, finally has to be executed. As exception has been handled so NEXT stmt after try-catch will be executed which is option D.
HTH
CMIW
PS: don't handle the exeception and see what happen


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
 
Don't get me started about those stupid light bulbs.
 
subject: Exceptions
 
Similar Threads
Exception
MindQ Q31
another question from MindQ Mock Exam
Question related to exception
From mIND q TEST some ques