blob: 6bd48f3b7b72861d6847fc599ecf8303d9b5af00 (
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
|
package pkg;
import java.lang.annotation.Annotation;
import org.aspectj.lang.reflect.MethodSignature;
public aspect SourceExceptionHandlerAspect {
pointcut handleSourceExceptionPointcut(): @annotation(HandleSourceException);
declare soft : SourceException : handleSourceExceptionPointcut();
Object around() throws TargetException: handleSourceExceptionPointcut() {
try {
return proceed();
} catch (Throwable exception) {
String message = "";
Annotation[] annotations = ((MethodSignature) thisJoinPoint.getSignature()).getMethod().getAnnotationsByType(HandleSourceException.class);
if (annotations.length == 1) {
message = ((HandleSourceException) annotations[0]).message();
}
if (message.isBlank()) {
message = exception.getMessage();
}
throw new TargetException(message, exception);
}
}
}
|