如何捕获 Spring AOP Advice 抛出的异常
我有自己的异常“MyOwnException”并从我的服务类中抛出此异常
public void service() throws MyOwnException
{
// some code
}
现在我想在建议中捕获 MyOwnException 并重新抛出一个全新的异常
public class SimpleThrowsAdvice implements ThrowsAdvice {
public void afterThrowing(Method method, Object[] args, Object target,
MyOwnException ex) throws Throwable {
throw new Exception("new Description",ex);
}
}
现在,我如何捕获重新抛出的异常来自上面的建议SimpleThrowsAdvice
?
I have my own exception "MyOwnException" and throw this exception from my service class
public void service() throws MyOwnException
{
// some code
}
Now I want to catch MyOwnException in an advice and rethrow a brand-new Exception
public class SimpleThrowsAdvice implements ThrowsAdvice {
public void afterThrowing(Method method, Object[] args, Object target,
MyOwnException ex) throws Throwable {
throw new Exception("new Description",ex);
}
}
Now, how can I catch the re-thrown Exception
from the above Advice SimpleThrowsAdvice
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用周围建议来做到这一点。请参阅此处 Spring AOP AfterThrowing 与 around Advice
You should use the Around advice to do that. See here Spring AOP AfterThrowing vs. Around Advice