Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Question from Enthuware

 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code snippet:


Which of the following statements are true?

A. If IOException gets thrown at line1, then the whole method will end up throwing SQLException.
B. If IOException gets thrown at line1, then the whole method will end up throwing CloneNotSupportedException.
C. If IOException gets thrown at line1, then the whole method will end up throwing InstantiationException()
D. If no exception is thrown at line1, then the whole method will end up throwing CloneNotSupportedException.
E. If SQLException gets thrown at line1, then the whole method will end up throwing InstantiationException()

Answers:- B, D

Could anybody please explain?

Thanks!!!


[HENRY: Added Code Tags]
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: Whatever the case finally block will always execute if your code reaches in try{}catch block, until you use System.exit();
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1--if there exists a finally block after try or catch block ,it does not matter(except system.exit) what happens in the try or catch block the finally block will be exectued.

one exception would be discarded if another exception is thrown before handling the first one.
Hope this two points help you in figuring out the answer.
[EDIT: Oops ! i did not notice punit's hint. Sorry gave away the answer ! !]
 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Punit and James. Thanks Henry for adding code tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic