javaclass

Changeset

134:69dd27ca4d7d
2005-01-21 Paul Boddie raw files shortlog changelog graph Added the start of a test program.
tests/ExceptionTest.java (file)
     1.1 --- a/tests/ExceptionTest.java	Tue Jan 18 17:47:24 2005 +0100
     1.2 +++ b/tests/ExceptionTest.java	Fri Jan 21 17:01:47 2005 +0100
     1.3 @@ -97,6 +97,35 @@
     1.4          }
     1.5          return x;
     1.6      }
     1.7 +
     1.8 +    public static void main(String[] args) {
     1.9 +        ExceptionTest test = new ExceptionTest();
    1.10 +        try {
    1.11 +            test.testThrow(0);
    1.12 +            System.err.println("testThrow(0) failed!");
    1.13 +        } catch (MyException exc) {
    1.14 +            System.out.println("testThrow(0) correct: " + exc);
    1.15 +        } catch (java.lang.Exception exc) {
    1.16 +            System.err.println("testThrow(0) failed (MyException expected)!");
    1.17 +        }
    1.18 +        try {
    1.19 +            test.testThrow(1);
    1.20 +            System.err.println("testThrow(1) failed!");
    1.21 +        } catch (MyOtherException exc) {
    1.22 +            System.out.println("testThrow(1) correct: " + exc);
    1.23 +        } catch (java.lang.Exception exc) {
    1.24 +            System.err.println("testThrow(1) failed (MyOtherException expected)!");
    1.25 +        }
    1.26 +        try {
    1.27 +            if (test.testThrow(2) != 1) {
    1.28 +                System.err.println("testThrow(2) failed!");
    1.29 +            } else {
    1.30 +                System.out.println("testThrow(2) correct.");
    1.31 +            }
    1.32 +        } catch (java.lang.Exception exc) {
    1.33 +            System.err.println("testThrow(2) failed (no exception expected)!");
    1.34 +        }
    1.35 +    }
    1.36  }
    1.37  
    1.38  class MyException extends java.lang.Exception {