Added
Link Here
|
1 |
import org.aspectj.lang.JoinPoint.StaticPart; |
2 |
|
3 |
import java.lang.annotation.Retention; |
4 |
import java.lang.annotation.RetentionPolicy; |
5 |
|
6 |
//@Retention(RetentionPolicy.RUNTIME) |
7 |
@interface NormalException { |
8 |
/** The default of Void means ANY throwable */ |
9 |
Class[] value() default Void.class; |
10 |
} |
11 |
|
12 |
public aspect ErrorHandling { |
13 |
|
14 |
before(Throwable throwable) : handler(*) && args(throwable) && !@withincode(NormalException) { |
15 |
System.err.println("Caught in "+thisEnclosingJoinPointStaticPart.getSignature().getName()); |
16 |
} |
17 |
|
18 |
public static void main(String argz[]) { |
19 |
new Test().checkConnection(); |
20 |
} |
21 |
} |
22 |
|
23 |
class Test { |
24 |
@NormalException(Exception.class) |
25 |
protected void checkConnection() { |
26 |
try { |
27 |
foo(); |
28 |
} catch (Exception e) { |
29 |
;//skip warning |
30 |
} |
31 |
} |
32 |
|
33 |
private void foo() { |
34 |
try { |
35 |
throw new RuntimeException(); |
36 |
} catch (RuntimeException e) { |
37 |
throw e; |
38 |
} |
39 |
} |
40 |
|
41 |
} |