javaclass

Changeset

16:eb6e8da8c28e
2004-11-09 Paul Boddie raw files shortlog changelog graph Added some test cases.
tests/ExceptionTest.java (file) tests/Value.java (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tests/ExceptionTest.java	Tue Nov 09 18:52:38 2004 +0100
     1.3 @@ -0,0 +1,35 @@
     1.4 +public class ExceptionTest {
     1.5 +
     1.6 +    public int testCatch() {
     1.7 +        try {
     1.8 +            throw new MyException();
     1.9 +        } catch (MyException exc) {
    1.10 +            return 1;
    1.11 +        }
    1.12 +    }
    1.13 +
    1.14 +    public int testFinally(int x) {
    1.15 +        try {
    1.16 +            if (x == 0) {
    1.17 +                throw new MyException();
    1.18 +            } else if (x == 1) {
    1.19 +                throw new MyOtherException();
    1.20 +            }
    1.21 +        } catch (MyException exc) {
    1.22 +            x = 3;
    1.23 +        } catch (MyOtherException exc) {
    1.24 +            x = 2;
    1.25 +        } finally {
    1.26 +            x = 1;
    1.27 +        }
    1.28 +        return x;
    1.29 +    }
    1.30 +}
    1.31 +
    1.32 +class MyException extends java.lang.Exception {
    1.33 +}
    1.34 +
    1.35 +class MyOtherException extends java.lang.Exception {
    1.36 +}
    1.37 +
    1.38 +// vim: tabstop=4 expandtab shiftwidth=4
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tests/Value.java	Tue Nov 09 18:52:38 2004 +0100
     2.3 @@ -0,0 +1,17 @@
     2.4 +public class Value {
     2.5 +    private int value;
     2.6 +
     2.7 +    public Value(int value) {
     2.8 +        this.value = value;
     2.9 +    }
    2.10 +
    2.11 +    public int getValue() {
    2.12 +        return this.value;
    2.13 +    }
    2.14 +
    2.15 +    public void setValue(int value) {
    2.16 +        this.value = value;
    2.17 +    }
    2.18 +}
    2.19 +
    2.20 +// vim: tabstop=4 expandtab shiftwidth=4