File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes MindQ Q31 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "MindQ Q31" Watch "MindQ Q31" New topic
Author

MindQ Q31

gosrai
Greenhorn

Joined: Feb 02, 2001
Posts: 3
Hi folks
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
According to me the answer should be.. b,c.
But the answers in MindQ site are b,c,d.
I am bit confused here. Please help
Ranjeeta

gosrai
Lokesh Mahajan
Greenhorn

Joined: Feb 01, 2001
Posts: 22
Hello Dear
This is like this in the example IllegalArgumentException thrown by the method fragile() is cought in the catch block(which prints"Exception thrown"),
than the finally block is executed(results in printing "Done with exceptions"
Now since the exception thrown by the method fragile() is caught by the try & catch block(though not immediate catch block but by the successive catch block)program does not terminates,but
it follows the steps bellow the method so resulting in printing "myMethod is done"
d will not have been option had the exception thrown is not caught & there by terminating the program.
lokesh mahajan
gosrai
Greenhorn

Joined: Feb 02, 2001
Posts: 3
Hi Lokesh
thanks a lot for your explanation.
I understand it now, that caught exceptions would not terminate the program but uncaught would.
I think overdoing creates more confusion.. I am realising this, day by day getting more
Ranjeeta
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MindQ Q31