[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] after() throwing matching on interface throws clauses rather than method implementation
|
Title: Message
Hi
Ian,
Could
you modify your 'after throwing()' to catch the Exceptions as follows
:
Catch
Exception1 -
after throwing(Exception1 e1) throws Exception1 : .....
Catch
Exception2 -
after throwing(Exception2 e2) throws Exception2 : .....
Catch
Exception1 & Exception2 -
after throwing(Exception e) throws Exception :
.....
Will
this give you what you are looking for?
HTH,
Fintan
I want to add an
"after () throwing" pointcut to these methods that catch any exceptions, do
some logging and then throw an expected exception type. The problem is
that the matching is done on the interface's throw clause and not the
implementation method's.
I have:
- after ()
throwing (RuntimeException s) throws Exception1 : execution (* *.*(..) throws
Exception1 { ... }
- after () throwing (RuntimeException s) throws Exception2 :
execution (* *.*(..) throws Exception2 { ... }
Unfortunately the
Exception1 clause matches against the method that throws Exception2. This causes a compile error.
Example Source
with comments
------------------------------------------------------
public class
Exception1 extends Exception {}
public class Exception2 extends Exception {}
public class
MyClass {
public interface
MyInterface {
public Object MyMethod() throws Exception1, Exception2;
}
private class InnerClass1 implements
MyInterface {
public Object MyMethod() throws Exception1 { return null; }
}
private class InnerClass2 implements MyInterface {
public Object MyMethod() throws Exception2 { return null;}
}
private class InnerClass3 implements MyInterface {
public Object MyMethod()
throws Exception1, Exception2 { return
null;}
}
}
//
// First
attempt
//
public aspect MyAspect {
// This matches against all 3
classes
// InnerClass2 causes an error
because this throws Exception1 but InnerClass2.MyMethod should only throw
Exception2
after () throwing (Exception e) throws
Exception1
: execution (* *.*(..) throws Exception1)
{}
// This
matches against all 3 classes
// InnerClass1 causes an error
because this throws Exception2 but InnerClass1.MyMethod should only throw
Exception1
after () throwing (Exception e) throws
Exception2
: execution (* *.*(..) throws Exception2)
{}
}
//
// Second
attempt
//
public aspect MyAspect {
// This matches against just
InnerClass1. Good.
after () throwing (Exception e) throws
Exception1
: execution (* *.*(..) throws Exception1, !Exception2)
{}
// This
matches against just InnerClass2. Good
after () throwing (Exception e) throws
Exception2
: execution (* *.*(..) throws Exception2, !Exception1)
{}
// This matches against all 3
classes.
//
InnerClass1 causes an error because this throws Exception2 but
InnerClass1.MyMethod should only throw Exception1
// InnerClass2
causes an error because this throws Exception1 but InnerClass2.MyMethod
should only throw Exception2
// InnerClass3 is fine
after ()
throwing (Exception e) throws Exception1, Exception2
: execution (*
*.*(..) throws Exception2, Exception1)
{}
}
* ** *** ** * ** *** ** * ** *** ** *
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed.
Any views or opinions presented are solely those of the author, and do not necessarily
represent those of ESB.
If you have received this email in error please notify the sender.
Although ESB scans e-mail and attachments for viruses, it does not guarantee
that either are virus-free and accepts no liability for any damage sustained
as a result of viruses.
* ** *** ** * ** *** ** * ** *** ** *