如何在AspectJ中的AfterThrowing中吞下异常 [英] How to swallow a exception at AfterThrowing in AspectJ
本文介绍了如何在AspectJ中的AfterThrowing中吞下异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在AspectJ中,我想吞下一个异常.
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();
}
}
上面,它没有吞下异常. testThrowable()的调用方仍然收到异常.我希望呼叫者不接收异常.怎么办呢? 谢谢.
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.
推荐答案
我认为不能在AfterThrowing
中完成.您需要使用Around
.
I think it can't be done in AfterThrowing
. You need to use Around
.
这篇关于如何在AspectJ中的AfterThrowing中吞下异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文