Versions Compared

Key

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

If In the presence of a finally clause is specified block, irrespective of whether the try or catch blocks execute to completion or not, the finally block is executed. Consequently, statements that cause the finally block to terminate abruptly may mask any thrown exceptions. Keywords like such as return, break, continue and throw should never be used within a finally block.

...

Code Block
bgColor#ccccff
class TryFinally {         
  private static boolean doLogic() {
    try {
      throw new IllegalStateException(); 
    }  
    finally {
      System.out.println("Caught Exception");
    }
    // any return statements must go here; applicable only when exception is thrown conditionally
  }

  public static void main(String[] args) {
    doLogic();	
  }
}

...