Can we throw an exception from "Catch" and "Finally" block? Thanks, Karthik
Joined: Dec 30, 2002
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 ]
Joined: Oct 21, 2002
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.