A handler for a supertype of the exception. : try catch « 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 » try catch 
5.9.2.A handler for a supertype of the exception.
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class MainClass{
  public static void main(String args[]) {
    try {
      RandomAccessFile raf = new RandomAccessFile("myfile.txt""r");
      byte b[] new byte[1000];
      raf.readFully(b, 01000);
    catch (FileNotFoundException e) {
      System.err.println("File not found");
      System.err.println(e.getMessage());
      e.printStackTrace();
    catch (IOException e) {
      System.err.println("IO Error");
      System.err.println(e.toString());
      e.printStackTrace();
    }
  }
}
5.9.try catch
5.9.1.Exceptions come in two flavors: checked and unchecked.
5.9.2.A handler for a supertype of the exception.
5.9.3.Multiple catch Clauses and Work with finally
5.9.4.A try block may contain code that throws different exception types.
5.9.5.Rethrow exception, no try...catch
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.