The finally Block : finally « Statements « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Statements » finally 
5.10.1.The finally Block
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.