Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
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.

...