Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] exceptions in around advice

Just to clarify my previous answer, I was assuming Mark needed to throw exceptions of different types (or call methods that might) from the advice, in which case it is subtle. As Ramnivas points out, if you merely want to propagate exceptions from the proceed, it happens automatically and your advice need not declare a throws clause. 

Ron

Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895

> ------------Original Message-------------
> From: Ramnivas Laddad <ramnivas@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Tue, Aug-19-2003 9:16 AM
> Subject: Re: [aspectj-users] exceptions in around advice
> 
> Mark,
> 
> Unless you are catching the exception thrown by proceed()
> (i.e. the join point execution), you don't need to do anything
> specific. You also do not need around() to declare throwing
> any exception. In other words, the propagation of exception
> that you are seeking happens automatically.
> 
> Object around() : executionOfIOExceptionThrowingMethods()
>                   || executionOfSQLExceptionThrowingMethods() {
>     ... some crosscutting logic
>     return proceed();
> }
> 
> The issue become when an around advice does want to catch the
> exception (very typical for transaction management, security
> and so on kind of concerns), what does it do with that exception?
> 
> Object around() : executionOfIOExceptionThrowingMethods()
>                   || executionOfSQLExceptionThrowingMethods() {
>     try {
>         ... some crosscutting logic
>         return proceed();
>     } catch(Exception ex) {
>         // crosscutting logic to handle failures
>         // *** Now what to do with the exception *** ?
>     }
> }
> 
> This is where you use the exception introduction pattern ("AspectJ
> in Action" chapter 8). Bascially it says: Throw the caught exception
> wrapped in a RuntimeException. It also provides a mechanism to 
> restore back the thrown exception so that the caller gets back the
> orginal checked exception.
> 
> -Ramnivas
> 
> --- "Volkmann, Mark" <Mark.Volkmann@xxxxxxxxxxxxx> wrote:
> > I've got an around advice that I want to apply to methods that throw
> > different types of exceptions.  If an exception is thrown in the
> > actual
> > method when I call proceed() then I want that exception to propagate
> > back to
> > the caller.  I can't say that advice throws java.lang.Exception
> > because then
> > callers would have to catch that instead of the specific kinds of
> > exceptions
> > that can really be thrown.  How can I get this to work?
> > 
> > 
> >
> ---------------------------------------------------------------------------------------------------------
> > A.G. Edwards & Sons' outgoing and incoming e-mails are electronically
> > archived and subject to review and/or disclosure to someone other 
> > than the recipient.
> > 
> >
> ---------------------------------------------------------------------------------------------------------
> > 
> 
> 
> =====
> Ramnivas Laddad
> Author, AspectJ in Action
> http://www.manning.com/laddad
> http://www.amazon.com/exec/obidos/ASIN/1930110936
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 


Back to the top