[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] extension of the handler pointcut

You don't need the proposed extension to achieve what you want.
You need to combiner an args() pointcut with handler() to 
capture the exception as follows:

aspect InsertCode {
    before(IOException e)
        : withincode(void Foo.bar())
        && handler(IOException) 
        && args(e) {              // This captures the exception
        e.printStackTrace();
    }    
}

-Ramnivas

--- Susumu YAMAZAKI <yamazaki@xxxxxxxxxxxxxxx> wrote:
> Dear all,
> 
> I propose to allow the "handler" to have not only a type pattern but
> also an ID.  Then, we can use thrown exception in the advice.  For
> example:
> 
> class Foo {
>     void bar() {
>         try {
>             ...
>         } catch(IOException e) {}
>     }
> }
> 
> aspect InsertCode {
>     before(IOException e)
>         : withincode(void Foo.bar())
>         && handler(e) {
>         e.printStackTrace();
>     }    
> }
> 
> I know you will say "Why don't you use after + throwing ?":
> 
> aspect InserCode {
>     after() throwing (IOException e) 
>         : call(void Foo.bar()) {
>         e.printStackTrace();
>     }
> }
> 
> My answer is that it forces Foo.bar() to declare "throws
> IOException".
> This causes two disadvantages: 
> 
> (1) The "after + throwing" advice will be helpless if Foo.bar()
>     catches IOException within itself.
> 
> (2) The caller of Foo.bar() must catch IOException, though it will be
>     caught in the "after + throwing" advice.
> 
> Susumu YAMAZAKI <yamazaki@xxxxxxxxxxxxxxx>
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-dev


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com