blob: 0b07335f41fd2a1dfe377636b349b64d04927a55 (
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
|
import org.aspectj.lang.JoinPoint.StaticPart;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
//@Retention(RetentionPolicy.RUNTIME)
@interface NormalException {
/** The default of Void means ANY throwable */
Class[] value() default Void.class;
}
public aspect ErrorHandling {
before(Throwable throwable) : handler(*) && args(throwable) && !@withincode(NormalException) {
System.err.println("Caught in "+thisEnclosingJoinPointStaticPart.getSignature().getName());
}
public static void main(String argz[]) {
new Test().checkConnection();
}
}
class Test {
@NormalException(Exception.class)
protected void checkConnection() {
try {
foo();
} catch (Exception e) {
;//skip warning
}
}
private void foo() {
try {
throw new RuntimeException();
} catch (RuntimeException e) {
throw e;
}
}
}
|