作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 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() 的调用者仍然收到异常。我希望来电者不要收到异常。怎么能做到这一点?谢谢。
最佳答案
我认为在AfterThrowing
中是做不到的。您需要使用 Around
。
关于java - 如何在 AspectJ 的 AfterThrowing 吞下异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4396167/
我是一名优秀的程序员,十分优秀!