File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes On Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "On Exception Handling" Watch "On Exception Handling" New topic

On Exception Handling

Karthik Balasubramanian
Ranch Hand

Joined: Dec 13, 2002
Posts: 43
Can we throw an exception from "Catch" and "Finally" block?
Shiva Mantri

Joined: Dec 30, 2002
Posts: 19
yes you can, but you will lose the exception information thrown from try clause, unless you log the exception information.

JLS11.3 Handling of an exception
If a try or catch block in a try-finally or try-catch-finally statement completes abruptly, then the finally clause is executed during propagation of the exception, even if no matching catch clause is ultimately found. If a finally clause is executed because of abrupt completion of a try block and the finally clause itself completes abruptly, then the reason for the abrupt completion of the try block is discarded and the new reason for abrupt completion is propagated from there.

[ January 28, 2003: Message edited by: Shiva Mantri ]
Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
Although in real world projects you rarely use the finally block, it is very common to catch one exception and throw another exception from the catch clause.
I agree. Here's the link:
subject: On Exception Handling
It's not a secret anymore!