Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring AOP Exception handling

 
Rakesh Jhamb
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

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.


Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post some example code on what you are doing in your advice method?

Mark
 
Rakesh Jhamb
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside the advice method, I am just logging it to a log file.
 
Rakesh Jhamb
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please respond back.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakesh Jhamb wrote:Please respond back.

PatienceIsAVirtue!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic