javaclass

Changeset

27:fe4821483813
2004-11-10 Paul Boddie raw files shortlog changelog graph Added an uncaught (and hence re-raised) exception to the testCatchFinally method. Added a method with multiple exception areas.
tests/ExceptionTest.java (file)
     1.1 --- a/tests/ExceptionTest.java	Wed Nov 10 17:11:44 2004 +0100
     1.2 +++ b/tests/ExceptionTest.java	Wed Nov 10 17:47:04 2004 +0100
     1.3 @@ -55,12 +55,14 @@
     1.4          return x;
     1.5      }
     1.6  
     1.7 -    public int testCatchFinally(int x) {
     1.8 +    public int testCatchFinally(int x) throws MyUncheckedException {
     1.9          try {
    1.10              if (x == 0) {
    1.11                  throw new MyException();
    1.12              } else if (x == 1) {
    1.13                  throw new MyOtherException();
    1.14 +            } else if (x == 2) {
    1.15 +                throw new MyUncheckedException();
    1.16              }
    1.17              x = 1;
    1.18          } catch (MyException exc) {
    1.19 @@ -72,6 +74,29 @@
    1.20          }
    1.21          return x;
    1.22      }
    1.23 +
    1.24 +    public int testMultipleCatch(int x, int y) {
    1.25 +        try {
    1.26 +            x = testThrow(x);
    1.27 +        } catch (MyException exc) {
    1.28 +            x = 3;
    1.29 +        } catch (MyOtherException exc) {
    1.30 +            x = 2;
    1.31 +        } catch (java.lang.Exception exc) {
    1.32 +            x = -1; // Should be unreachable, really.
    1.33 +        }
    1.34 +
    1.35 +        try {
    1.36 +            x += 10 * testThrow(y);
    1.37 +        } catch (MyException exc) {
    1.38 +            x += 30;
    1.39 +        } catch (MyOtherException exc) {
    1.40 +            x += 20;
    1.41 +        } catch (java.lang.Exception exc) {
    1.42 +            x += -10; // Should be unreachable, really.
    1.43 +        }
    1.44 +        return x;
    1.45 +    }
    1.46  }
    1.47  
    1.48  class MyException extends java.lang.Exception {
    1.49 @@ -80,4 +105,7 @@
    1.50  class MyOtherException extends java.lang.Exception {
    1.51  }
    1.52  
    1.53 +class MyUncheckedException extends java.lang.Exception {
    1.54 +}
    1.55 +
    1.56  // vim: tabstop=4 expandtab shiftwidth=4