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
精彩评论