【发布时间】:2023-03-21 11:45:01
【问题描述】:
在 AspectJ 中,我想吞下一个异常。
@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() 的调用者仍然收到异常。我希望来电者不要收到异常。怎么能做到这一点? 谢谢。
【问题讨论】: