blob: 40e33f0465e3e05b1d60897fb627f6d0a7bef55b (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
import org.aspectj.testing.Tester;
import java.io.IOException;
public class AdviceThrowsCp {
public static void main(String[] args) {
try {
new C().m1();
Tester.checkFailed("m1");
} catch (CheckedExc ce) {
Tester.checkEqual("b1", ce.getMessage(), "m1");
}
try {
new C().m2();
Tester.checkFailed("m2");
} catch (UncheckedExc ce) {
Tester.checkEqual("b3", ce.getMessage(), "m2");
}
try {
new C().m3();
Tester.checkFailed("m3");
} catch (CheckedExc ce) {
Tester.checkEqual("b1", ce.getMessage(), "m3");
} catch (Exception e) {
Tester.checkFailed("IOException");
System.out.println("m3: " + e);
}
try {
new C().m4();
Tester.checkFailed("m4");
} catch (UncheckedExc ce) {
Tester.checkEqual("b3", ce.getMessage(), "m4");
}
}
}
class CheckedExc extends Exception {
CheckedExc(String m) { super(m); }
}
class UncheckedExc extends RuntimeException {
UncheckedExc(String m) { super(m); }
}
class C {
public void m1() throws CheckedExc {
}
public void m2() throws UncheckedExc {
}
public void m3() throws IOException, CheckedExc {
}
public void m4() {
}
}
aspect A {
pointcut canThrowChecked(): call(* C.m1()) || call(* C.m3());
pointcut canThrowChecked1(): call(* C.m*() throws CheckedExc);
pointcut canThrowUnchecked(): call(* C.m*());
before() throws CheckedExc: canThrowChecked() {
throw new CheckedExc("b1");
}
before() throws CheckedExc: canThrowChecked1() {
throw new CheckedExc("b2");
}
before() throws UncheckedExc: canThrowUnchecked() {
throw new UncheckedExc("b3");
}
before(): canThrowUnchecked() {
throw new UncheckedExc("b4");
}
void around() throws CheckedExc: canThrowChecked() {
throw new CheckedExc("a1");
}
void around() throws CheckedExc: canThrowChecked1() {
throw new CheckedExc("a2");
}
void around() throws UncheckedExc: canThrowUnchecked() {
throw new UncheckedExc("a3");
}
void around(): canThrowUnchecked() {
throw new UncheckedExc("a4");
}
}
|