File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes AOP pointcut at CATCH block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "AOP pointcut at CATCH block" Watch "AOP pointcut at CATCH block" New topic
Author

AOP pointcut at CATCH block

Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Mark: using Spring? I didn't know that--this could be useful; nobody lets me use compile-time AspectJ.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Sep 29, 2008
Posts: 12617

Oh, wait, maybe I knew that. I thought the OP meant within the method, not if the entire method threw.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AOP pointcut at CATCH block
 
Similar Threads
aop and transations
Spring AOP and AspectJ Integration with EJB3
AOP
Transaction demarcation works with TransactionProxy but not AOP
Spring Aop