• 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

A question in finally

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers
I came accross a question (given below) while preparing for scjp .The question goes like this

Which statement is true?
A A try statement must have at least one corresponding catch block.
B Multiple catch statements can catch the same class of exception more than once.
C An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method.
D Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute.
E Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block must always run to completion.

Answer: E

I think the answer given by author is incorrect (to my knowledge it will be option

D

)because we can't be sure of completion of finally block as it may also throw any exception of it own.What you guys think about it ?.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of cource, we can't be sure of completion of finally block . But the finally block will be executing until it is not finished. If finally block throw exception than on the top of stack trace we will have this exception
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Simeon Cherniy:
Of cource, we can't be sure of completion of finally block . But the finally block will be executing until it is not finished. If finally block throw exception than on the top of stack trace we will have this exception



Simeon, check this code:



The output is "was thrown in finally" and nothing more.

So, the author of this topic is absolutely right, the answer should be "D"
 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ivan
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Answer D makes more sence since we cannot control finish of finally rather than start E sounds bit odd.
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic