paul@16 | 1 | public class ExceptionTest { |
paul@16 | 2 | |
paul@16 | 3 | public int testCatch() { |
paul@16 | 4 | try { |
paul@16 | 5 | throw new MyException(); |
paul@16 | 6 | } catch (MyException exc) { |
paul@16 | 7 | return 1; |
paul@16 | 8 | } |
paul@16 | 9 | } |
paul@16 | 10 | |
paul@16 | 11 | public int testFinally(int x) { |
paul@16 | 12 | try { |
paul@16 | 13 | if (x == 0) { |
paul@16 | 14 | throw new MyException(); |
paul@16 | 15 | } else if (x == 1) { |
paul@16 | 16 | throw new MyOtherException(); |
paul@16 | 17 | } |
paul@16 | 18 | } catch (MyException exc) { |
paul@16 | 19 | x = 3; |
paul@16 | 20 | } catch (MyOtherException exc) { |
paul@16 | 21 | x = 2; |
paul@16 | 22 | } finally { |
paul@16 | 23 | x = 1; |
paul@16 | 24 | } |
paul@16 | 25 | return x; |
paul@16 | 26 | } |
paul@16 | 27 | } |
paul@16 | 28 | |
paul@16 | 29 | class MyException extends java.lang.Exception { |
paul@16 | 30 | } |
paul@16 | 31 | |
paul@16 | 32 | class MyOtherException extends java.lang.Exception { |
paul@16 | 33 | } |
paul@16 | 34 | |
paul@16 | 35 | // vim: tabstop=4 expandtab shiftwidth=4 |