I read about spring AOP exception handling... I was able to successfully create a advice and that advice is being invoked whenever the exception occurs in my application.
My question is that thought the advice is being invoked for exceptions, but my exception is still not caught inside the advice...the advice class's method gets executed and the exception is still thrown and the stack trace is printed.
Can I not configure an advice in the application that catches the exception whenever an exception is thrown inside the application.
Or maybe I am understanding the design of AOP exception handling in a wrong manner, please throw some light on this problem.
Rakesh Jhamb wrote:Inside the advice method, I am just logging it to a log file.
Exactly, so you are then going to see
but my exception is still not caught inside the advice...the advice class's method gets executed and the exception is still thrown and the stack trace is printed.
You have to do something with your exception or not allow the exception to be thrown through the method. Remember one of the parameters is the Exception. Usually what people do is check the type of the Exception (for a generic exception handler) or if it is specific then they already know the type of the Exception. But you can then rewrap the exception to throw a more "client" approved exception, so that the clients see a prettier display.