views:

28

answers:

1

I have my own exeception "MyOwnExeception" and throw this exeception from my service class

public void service() throws MyOwnExeception
{
// some code 

}

Now I want to catch MyOwnExeception in an advice and rethrow a brand-new Exeception

public class SimpleThrowsAdvice implements ThrowsAdvice {

    public void afterThrowing(Method method, Object[] args, Object target,
                MyOwnExeception ex) throws Throwable {

    throw new Exception("new Description",ex);
    }
}

Now,I want to catch the re-thrown "Exception" from the above Advice "SimpleThrowsAdvice ",

How I can catch exeception "Exeception"?.

+2  A: 

You should use the Around advice to do that. See here http://stackoverflow.com/questions/2501955/spring-aop-afterthrowing-vs-around-advice

Bytecode Ninja