In AspectJ, I want to swallow a exception.
@Aspect
public class TestAspect {
@Pointcut("execution(public * *Throwable(..))")
void throwableMethod() {}
@AfterThrowing(pointcut = "throwableMethod()", throwing = "e")
public void swallowThrowable(Throwable e) throws Exception {
logger.debug(e.toString());
}
}
public class TestClass {
public void testThrowable() {
throw new Exception();
}
}
Above, it didn't swallow exception. The testThrowable()'s caller still received the exception. I want caller not to receive exception. How can do this? Thanks.
I think it can't be done in
AfterThrowing
. You need to useAround
.My solution!
Thanks again.