According to the Java Language Specification:
If there are any enclosing try statements whose try blocks contain the throw statement, then any finally clauses of those try statements are executed as control is transferred outward, until the thrown value is caught. Note that abrupt completion of a finally clause can disrupt the transfer of control initiated by a throw statement.
Other than returning inside a finally block, what other ways are there?
Throwing an exception from a finally block will also clobber the original exception (if any).
EDIT: Found a reference explaining "abrupt completion".
From §14.1: Normal and Abrupt Completion of Statements:
An abrupt completion always has an associated reason, which is one of the following:
- A break with no label
- A break with a given label
- A continue with no label
- A continue with a given label
- A return with no value
- A return with a given value
- A throw with a given value, including exceptions thrown by the Java virtual machine
The last three are the only ones possible in a finally
clause, unless it is inside a loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With