Skip to main content

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

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>


Back to the top