• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AOP pointcut at CATCH block

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic