Exceptions

class Exception1 extends Exception {}
class Exception2 extends Exception {}
class Exception3 extends Exception {}
public class Exceptions {
    public static void main(String[]args) throws Exception3{
        try {
	    f(0);   // or f(1) or f(2) or f(3)
	    System.out.println("OK");
	}
	catch (Exception1 ex1) {
	    System.out.println("main caught Exception1");
	}
    }
    public static void f(int x) throws Exception1, Exception3 {
	if (x==1)
	    throw new Exception1();
	try {
	    g(x);
	}
	catch (Exception2 ex2) {
	    System.out.println("f() caught Exception2");
	}
    }
    public static void g(int x) throws Exception2, Exception3 {
	if (x==2)
	    throw new Exception2();
	h(x);
    }
    public static void h(int x) throws Exception3 {
	if (x==3)
	    throw new Exception3();
    }
}
  
  
allan gottlieb