Exception Handling in Java



General Information

Try/Catch Statement and Predefined Exceptions

Exceptions as Values

Catch or Declare

Errors

Can't catch ...Errors including

Propagation

class Demo {
   static void A() {
      throw new RuntimeException ();
   }
   static void B() {
     try {
        A();
     } catch (IOException e){
        System.out.println ("B caught IOException");
     }
   }
   public static void main (String[] args) {
     try {
        B();
     } catch (NullPointerException e) {
        System.out.println ("main caught NullPointerException");
     }
   }
}

Throwables in the Core Libraries

An overview of exceptions and errors in the Java core libraries. No floating point overflow or underflow, but there is an exception for divide-by-zero (ArithmeticException). Arrays are always checked (ArrayIndexOutOfBoundsException). Very common NullPointerException.

Finally Clause

Performance Considerations

Java virtual machine uses the range table approach with no performance penality programs that does not raise exceptions.

Chained Exceptions

Recursion

The confusion that may arise with local exceptions and recursion is untangled the same way as local classes because exceptions are classes. Exceptions are not generative values as in SML.
Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Thu Jan 29 09:59:30 EST 2004