2

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?

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
sajeyasok
  • 21
  • 1
  • 2
  • Are you sure you want to re-catch the already-caught-but-now-wrapped exception? This sounds too much like it's turtles all the way down. What do you intend to do with the new Exception catching advice that you can't do with SimpleThrowsAdvice? – earldouglas Sep 07 '10 at 15:23

1 Answers1

4

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

Community
  • 1
  • 1
Behrang
  • 46,888
  • 25
  • 118
  • 160