...
Code Block | ||
---|---|---|
| ||
class TryFinally { private static boolean doLogic() { try { throw new IllegalStateException(); } finally { System.out.println("Uncaught Exception"); return true; } } public static void main(String[] args) { doLogic(); } } |
When the IllegalStateException
is thrown, it does not propagate all the way up through the call stack. Rather, The IllegalStateException
is suppressed by the abrupt termination of the finally
block suppresses the IllegalStateException
because it the return statement becomes the final cause of abrupt termination of the try
blockcaused by the return
statement.
Compliant Solution
This compliant solution removes the return
statement from the finally
block.
...