File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question in finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question in finally " Watch "A question in finally " New topic
Author

A question in finally

Ajit Amitav Das
Ranch Hand

Joined: Dec 14, 2005
Posts: 49
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 ?.


Warm Regards<br />Ajit Amitav Das<br />SCJP 1.5
Simeon Cherniy
Greenhorn

Joined: Jul 26, 2006
Posts: 21
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


5-year Student of <br />Moscow Institute of Physics and Technology.
Ivan Rebrov
Ranch Hand

Joined: Jul 09, 2006
Posts: 30
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"


SCJP 5.0 - 95%<br />Preparing for SCWCD
Ajit Amitav Das
Ranch Hand

Joined: Dec 14, 2005
Posts: 49
Thanks Ivan
joy peter
Greenhorn

Joined: Aug 29, 2006
Posts: 13
Hi,
Answer D makes more sence since we cannot control finish of finally rather than start E sounds bit odd.


Awake Arise and Stop Not Till Your goal is reached
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question in finally
 
Similar Threads
Exceptions doubt??
COnfusion About Unreachable Code
help me. confused with exception
Return from finally block
return of the try-catch