开发者

How to catch the exception thrown from a Spring AOP Advice

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);开发者_StackOverflow中文版
    }
}

Now, how can I catch the re-thrown Exception from the above Advice SimpleThrowsAdvice?


You should use the Around advice to do that. See here Spring AOP AfterThrowing vs. Around Advice

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜