class TestExceptionHandling{

    public static void main(String[] args){
    
        try {
            method1();
        } catch ( Method1Exception e ) {
            System.out.println("Method1Exception caught in main.");
        } catch ( Method2Exception e ) {
            System.out.println("Method2Exception caught in main.");
        } finally {
            System.out.println("main finally clause");
        }   
        
        // code continues on normally
        System.out.println("Out of try block");
    }
    
    static void method1() throws Method1Exception,
                                 Method2Exception
    {
        try {
            System.out.println("In Method1");
            method3();
        } catch (Method3Exception e) {
            System.out.println("Method3Exception caught in method1");
            throw new Method2Exception();
        } finally {
            System.out.println("method 1 finally clause");
        }               
    }
    
    static void method2() throws Method3Exception
    {
        System.out.println("In method2");
        method3();      
    }
    
    static void method3() throws Method3Exception {
        System.out.println("In method3");
        throw new Method3Exception();
    }

}

class Method1Exception extends Exception {}
class Method2Exception extends Exception {}
class Method3Exception extends Exception {}
