javaclass

Change of tests/ExceptionTest.java

157:2485a9127f2a
tests/ExceptionTest.java
     1.1 --- a/tests/ExceptionTest.java	Sun Jan 23 21:32:26 2005 +0100
     1.2 +++ b/tests/ExceptionTest.java	Sun Jan 23 21:32:42 2005 +0100
     1.3 @@ -1,4 +1,5 @@
     1.4  public class ExceptionTest {
     1.5 +    public int last;
     1.6  
     1.7      public int testThrow(int x) throws java.lang.Exception {
     1.8          if (x == 0) {
     1.9 @@ -51,6 +52,7 @@
    1.10              x = 1;
    1.11          } finally {
    1.12              x += 10;
    1.13 +            last = x;
    1.14          }
    1.15          return x;
    1.16      }
    1.17 @@ -71,6 +73,7 @@
    1.18              x = 2;
    1.19          } finally {
    1.20              x += 10;
    1.21 +            last = x;
    1.22          }
    1.23          return x;
    1.24      }
    1.25 @@ -125,6 +128,117 @@
    1.26          } catch (java.lang.Exception exc) {
    1.27              System.err.println("testThrow(2) failed (no exception expected)!");
    1.28          }
    1.29 +
    1.30 +        if (test.testCatch(0) != 3) {
    1.31 +            System.err.println("testCatch(0) failed!");
    1.32 +        } else {
    1.33 +            System.out.println("testCatch(0) correct.");
    1.34 +        }
    1.35 +        if (test.testCatch(1) != 2) {
    1.36 +            System.err.println("testCatch(1) failed!");
    1.37 +        } else {
    1.38 +            System.out.println("testCatch(1) correct.");
    1.39 +        }
    1.40 +        if (test.testCatch(2) != 1) {
    1.41 +            System.err.println("testCatch(2) failed!");
    1.42 +        } else {
    1.43 +            System.out.println("testCatch(2) correct.");
    1.44 +        }
    1.45 +
    1.46 +        if (test.testIncomingCatch(0) != 3) {
    1.47 +            System.err.println("testIncomingCatch(0) failed!");
    1.48 +        } else {
    1.49 +            System.out.println("testIncomingCatch(0) correct.");
    1.50 +        }
    1.51 +        if (test.testIncomingCatch(1) != 2) {
    1.52 +            System.err.println("testIncomingCatch(1) failed!");
    1.53 +        } else {
    1.54 +            System.out.println("testIncomingCatch(1) correct.");
    1.55 +        }
    1.56 +        if (test.testIncomingCatch(2) != 1) {
    1.57 +            System.err.println("testIncomingCatch(2) failed!");
    1.58 +        } else {
    1.59 +            System.out.println("testIncomingCatch(2) correct.");
    1.60 +        }
    1.61 +
    1.62 +        try {
    1.63 +            test.testFinally(0);
    1.64 +            System.err.println("testFinally(0) failed!");
    1.65 +        } catch (MyException exc) {
    1.66 +            if (test.last == 13) {
    1.67 +                System.out.println("testFinally(0) correct: set " + test.last);
    1.68 +            } else {
    1.69 +                System.err.println("testFinally(0) failed: set " + test.last);
    1.70 +            }
    1.71 +        } catch (java.lang.Exception exc) {
    1.72 +            System.err.println("testFinally(0) failed!");
    1.73 +        }
    1.74 +        try {
    1.75 +            test.testFinally(1);
    1.76 +            System.err.println("testFinally(1) failed!");
    1.77 +        } catch (MyOtherException exc) {
    1.78 +            if (test.last == 12) {
    1.79 +                System.out.println("testFinally(1) correct: set " + test.last);
    1.80 +            } else {
    1.81 +                System.err.println("testFinally(1) failed: set " + test.last);
    1.82 +            }
    1.83 +        } catch (java.lang.Exception exc) {
    1.84 +            System.err.println("testFinally(1) failed!");
    1.85 +        }
    1.86 +        try {
    1.87 +            if (test.testFinally(2) != 11) {
    1.88 +                System.err.println("testFinally(2) failed!");
    1.89 +            } else {
    1.90 +                System.out.println("testFinally(2) correct.");
    1.91 +            }
    1.92 +        } catch (java.lang.Exception exc) {
    1.93 +            System.err.println("testFinally(2) failed!");
    1.94 +        }
    1.95 +
    1.96 +        try {
    1.97 +            if (test.testCatchFinally(0) != 13) {
    1.98 +                System.err.println("testCatchFinally(0) failed!");
    1.99 +            } else {
   1.100 +                System.out.println("testCatchFinally(0) correct.");
   1.101 +            }
   1.102 +        } catch (MyUncheckedException exc) {
   1.103 +            System.err.println("testCatchFinally(0) failed!");
   1.104 +        }
   1.105 +        try {
   1.106 +            if (test.testCatchFinally(1) != 12) {
   1.107 +                System.err.println("testCatchFinally(1) failed!");
   1.108 +            } else {
   1.109 +                System.out.println("testCatchFinally(1) correct.");
   1.110 +            }
   1.111 +        } catch (MyUncheckedException exc) {
   1.112 +            System.err.println("testCatchFinally(0) failed!");
   1.113 +        }
   1.114 +        try {
   1.115 +            test.testCatchFinally(2);
   1.116 +            System.err.println("testCatchFinally(2) failed!");
   1.117 +        } catch (MyUncheckedException exc) {
   1.118 +            if (test.last != 12) {
   1.119 +                System.err.println("testCatchFinally(2) failed!");
   1.120 +            } else {
   1.121 +                System.out.println("testCatchFinally(2) correct.");
   1.122 +            }
   1.123 +        }
   1.124 +
   1.125 +        if (test.testMultipleCatch(0, 1) != 23) {
   1.126 +            System.err.println("testMultipleCatch(0, 1) failed!");
   1.127 +        } else {
   1.128 +            System.out.println("testMultipleCatch(0, 1) correct.");
   1.129 +        }
   1.130 +        if (test.testMultipleCatch(1, 2) != 12) {
   1.131 +            System.err.println("testMultipleCatch(1, 2) failed!");
   1.132 +        } else {
   1.133 +            System.out.println("testMultipleCatch(1, 2) correct.");
   1.134 +        }
   1.135 +        if (test.testMultipleCatch(2, 0) != 31) {
   1.136 +            System.err.println("testMultipleCatch(2, 0) failed!");
   1.137 +        } else {
   1.138 +            System.out.println("testMultipleCatch(2, 0) correct.");
   1.139 +        }
   1.140      }
   1.141  }
   1.142