summaryrefslogtreecommitdiffstats
path: root/tests/base/test134/Driver.java
blob: ac5d54e5e040b8f60a97660d6903583a972a808b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import org.aspectj.testing.Tester;

public class Driver {
    public static void main(String[] args) { test(); }
    public int divide(int x, int y) {
        return x/y;
    }

    public static void test() {
        Tester.checkEqual(new Driver().divide(6, 3), 2, "divide(6, 3)");
        Tester.checkEqual(new Driver().divide(6, 0), -1, "divide(6, 0)");
    }
}

aspect CatchArithmetic {
    int around(): target(*) && call(int *(..)) {
        int x;
        try {
            x = proceed();
        }
        catch (ArithmeticException e) {
            return -1;
        }
        return x;
    }
}