• 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

Exception Question from Enthuware

 
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Punit and James. Thanks Henry for adding code tags.
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic