Development Java Tutorial

A finally block is always executed, regardless of whether or not exceptions are thrown.

import java.io.IOException;
public class MainClass {
  public static void main(String[] args) {
    try {
      System.out.println("In second try block in main()");
      System.in.read();
      return;
    } catch (IOException e) {
      System.out.println("I/O exception caught in main()");
    } finally {
      System.out.println("finally block for second try block in main()");
    }
    System.out.println("Code after second try block in main()");
  }
}
In second try block in main()
finally block for second try block in main()