• 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

MindQ Q31

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic