package dk.itu.oop.lecture8; class TryCatchExample{ static class ExceptionA extends Exception { int n; ExceptionA(int n){this.n = n;} public String toString(){return "A: " + n;} }; static class ExceptionB extends Exception { int n; ExceptionB(int n){this.n = n;} public String toString(){return "B: " + n;} }; static class ExceptionC extends ExceptionA{ ExceptionC(int n){super(n);}; public String toString(){return "C: " + n;} } static void pip(int i) throws ExceptionA{ if (i>4) throw new ExceptionA(i); else throw new ExceptionC(i); } static int pap(int i) throws ExceptionB { if (i<0) throw new ExceptionB(i); else try{ pip(i); return 7; }catch(ExceptionC ec){ try{ return pap(i-2); }catch(ExceptionB eb){ return eb.n; }finally{ System.out.println("Finally inner pap"); } }catch(ExceptionA ea){ throw new ExceptionB(i); }finally{ System.out.println("Finally outer pap"); } } public static void main(String[] a){ try{ System.out.println("pap returned: " + pap(1) ); }catch(ExceptionB eb){ System.out.println("pap failed:" + eb); } } }