wood burning stoves 2.0*
The moose likes Mock Exam Errata and the fly likes Round up question #132 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Round up question #132" Watch "Round up question #132" New topic
Author

Round up question #132

Thiru Narayanan
Greenhorn

Joined: Apr 30, 2001
Posts: 23
(#132) TRUE or FALSE: if an exception is not caught, the finally block will run and the rest of the method is skipped.
Answer: TRUE
The finally block will always run if an exception is thrown, and then the exception is immediately passed to the calling method.
My Doubt : The question talks about "exception is not caught". But the answer talks about "exception is thrown"
Can somebody please clarify?
Annie Weaver
Ranch Hand

Joined: Apr 17, 2001
Posts: 50
If you have a finally block, first you must have a try block where the exception is thrown from.
If there is no matching catch block, or no catch block at all, the exception is not caught in that method, but rather thrown to the calling method.
Any code following where the exception was thrown is skipped, up to the finally block. The finally block executes, then you go back to the calling method with the exception.
Thiru Narayanan
Greenhorn

Joined: Apr 30, 2001
Posts: 23
Thank you Annie.
Can anybody please clarify one more point.
If a value is returned from the 'finally' block, when the exception is not caught what will happen?
THIRU
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Thiru,
Anything that gets executed in the finally block will change the output of the method. If you decide to send a good return value then you will override the uncaught exception with a good value. Also if your finally method throws another exception and that is also uncaught it will then override the original uncaught exception and be thrown from the method. The following code example show how the finally block can send back good data which nullifies the uncaught exception throw.

Regards,
Manfred.
Thiru Narayanan
Greenhorn

Joined: Apr 30, 2001
Posts: 23
Thank you Manfred,
That is really useful.
THIRU
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Round up question #132
 
Similar Threads
rules roundup-ERROR
Aquestion from the test #132
finally in try/catch Mock exam
question in the test
Roundup question #132