blob: 93081b55759aa77edc459880a8330e6d0f59c0ec (
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
|
import java.io.*;
abstract aspect ExceptionHandling<T extends Throwable> {
protected abstract void onException(T anException);
protected abstract pointcut inExceptionHandlingScope();
declare soft: T : inExceptionHandlingScope();
after() throwing (T anException) : inExceptionHandlingScope() {
onException(anException);
}
}
public aspect DeclareSoftWithTypeVars extends ExceptionHandling<IOException>{
protected pointcut inExceptionHandlingScope() :
call(* doIO*(..));
protected void onException(IOException ex) {
System.err.println("handled exception: " + ex.getMessage());
throw new MyDomainException(ex);
}
public static void main(String[] args) {
C c = new C();
try {
c.doIO();
} catch (MyDomainException ex) {
System.err.println("Successfully converted to domain exception");
}
}
}
class C {
public void doIO() throws IOException {
throw new IOException("io, io, it's off to work we go...");
}
}
class MyDomainException extends RuntimeException {
public MyDomainException(Throwable t) {
super(t);
}
}
|