1 public class ExceptionTest { 2 3 public int testCatch() { 4 try { 5 throw new MyException(); 6 } catch (MyException exc) { 7 return 1; 8 } 9 } 10 11 public int testFinally(int x) throws java.lang.Exception { 12 try { 13 if (x == 0) { 14 throw new MyException(); 15 } else if (x == 1) { 16 throw new MyOtherException(); 17 } 18 } finally { 19 x = 1; 20 } 21 return x; 22 } 23 24 public int testCatchFinally(int x) { 25 try { 26 if (x == 0) { 27 throw new MyException(); 28 } else if (x == 1) { 29 throw new MyOtherException(); 30 } 31 } catch (MyException exc) { 32 x = 3; 33 } catch (MyOtherException exc) { 34 x = 2; 35 } finally { 36 x = 1; 37 } 38 return x; 39 } 40 } 41 42 class MyException extends java.lang.Exception { 43 } 44 45 class MyOtherException extends java.lang.Exception { 46 } 47 48 // vim: tabstop=4 expandtab shiftwidth=4