This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AOP pointcut at CATCH block

 
Anant Jagania
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have seen AOP pointcut for method execution but is it possible to have pointcut for catch block. Something like expression("catch()")?

I can overcome this situation by having the code in my method and make it throw the exception. But at some places i would not like to do that.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not using Spring AOP: Spring AOP (2.5)
Spring AOP currently supports only method execution join points[...]

If you need further capability you'd want to look at pure AspectJ (or other AOP implementation).
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sort of. Not at catching line, but you can create an afterThrowing advice, which is a clean approach to exception handling. If your method that matches the point cut expression throws and exception, then the after throwing advice will get called.

Mark
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Mark: using Spring? I didn't know that--this could be useful; nobody lets me use compile-time AspectJ.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:@Mark: using Spring? I didn't know that--this could be useful; nobody lets me use compile-time AspectJ.


Yep Spring AOP has 5 advice types

Before
AfterReturning, called after the target, but only if the target successfully returned.
AfterThrowing, called after the target, but only if the target throws an exception.
After, always called after the target.
Around, called before and after, but you are responsible for calling the target with a call to ProceedingJoinpoint's proceed method. And you are responsible for returning the target's return object from the advice method.

Mark
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, wait, maybe I knew that. I thought the OP meant within the method, not if the entire method threw.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Oh, wait, maybe I knew that. I thought the OP meant within the method, not if the entire method threw.


Yep still at the beginning or end of the method. So in the catch, if they need to catch anymore, throw and exception out of the method. Same results as if you could join at the catch line in the middle of the method.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic