开发者

How to catch the exception thrown from a Spring AOP Advice

开发者 https://www.devze.com 2023-01-10 11:28 出处:网络
I have my own exception \"MyOwnException\" and throw this exception from my service class public void service() throws MyOwnException

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

精彩评论

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