Multiple catch Clauses and Work with finally : try catch « Statements « SCJP






If a try statement has a finally clause, 
the finally block is always executed unless the Thread executing the try dies. 

public class MainClass{
    public static void main(String[] argv){

    }
    public int testX( String x){
      try {
        return someMethod( x );
      }catch( NullPointerException nex ){
        System.out.print("NullPointer, " );
        return -1 ;
      }catch( RuntimeException rex){
        System.out.print("Runtime ");
        return -2; 
      }finally{
        System.out.println("Finally");
      }
    }
    
    private int someMethod(String x){
      return 0;
    }
}








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