The finally Block : finally « Statements « SCJP






import java.io.File;
import java.io.IOException;

public class MainClass {
  public static void main(String[] argv) {
    File myFile = new File(".");
    String s = "not a number";

    try {
      System.out.println("About to call.");
      int x = Integer.parseInt(s);
      myFile.getCanonicalFile();
      System.out.println("Call succeeded.");
    }

    catch (NumberFormatException xceptn) {
      System.out.println("Bad text! " + xceptn.getMessage());
      xceptn.printStackTrace();
    }

    catch (IOException xceptn) {
      System.out.println("File stress! " + xceptn.getMessage());
      xceptn.printStackTrace();
    }

    finally {
      System.out.println("In the finally block.");
    }

  }
}
About to call.
Bad text! For input string: "not a number"
java.lang.NumberFormatException: For input string: "not a number"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
	at java.lang.Integer.parseInt(Integer.java:447)
	at java.lang.Integer.parseInt(Integer.java:497)
	at MainClass.main(MainClass.java:11)
In the finally block.








5.10.finally
5.10.1.The finally Block