Thursday, December 9, 2010

Never abruptly exit a finally block

Every finally block should complete normally, barring an unchecked exception.
Never exit a finally block with a return, break, continue, or throw, and never allow a checked exception to propagate our of a finally block.
When both try block and the finally block complete abruptly, the reason for the abrupt completion in the try block is discarded. Discarding the reason for abrupt completion is almost never what you want ... (Java Puzzlers p.78)


References:
http://accu.org/index.php/journals/236 (handle checked exception in finally block)
http://www.javamex.com/tutorials/exceptions/exceptions_finally.shtml
http://www.javamex.com/tutorials/exceptions/exceptions_hierarchy.shtml

No comments: