|
|
|
|
|
Re: Catch Exception instance in advice for handler pointcut [message #46432 is a reply to message #46374] |
Mon, 17 January 2005 15:07  |
Eclipse User |
|
|
|
Originally posted by: newsserver_mails.bodden.de
On Mon, 17 Jan 2005 17:05:30 +0000 (UTC), harry sheng wrote:
> thisJoinPoint.getTarget() always returns "null" no matter where the "catch
> (MyException ex)" block is.
Of course those do not work for every pointcut! For ahandler pointcut there
is not "target" or "this". Those are specified e.g. for call pointcuts
where "target" is the object being called and "this" is the object
dispatching the call...
Eric
--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
How to remove incorrectly marked bad secotrs on NTFS...
http://bodden.de/misc/ntfsrecovery/
|
|
|
|
Re: Catch Exception instance in advice for handler pointcut [message #585859 is a reply to message #46197] |
Sun, 16 January 2005 21:45  |
Eclipse User |
|
|
|
Eric Bodden wrote:
> On Fri, 14 Jan 2005 16:33:26 +0000 (UTC), Harry Sheng wrote:
>> Is it possible to catch the Exception instance in advice for handler
>> pointcut?
> Try the following:
> after() throwing (Exception theException) {
> //do something with theException
> }
What I am looking for is to cut into the "catch (MyException ex) { ... }"
block with the a advice like the following,
before(): handler (MyException+) {
// I want to access to the following inside this advice
// 1. the exception instance
// 2. the signature of the method inside which the exception is
caught
// 3. the object instance which catches and handles the exception
}
I can only use before() advice for "handler()" pointcut. "this()" or
"target()"
cannot be used together with "handler()". I can get the object instance
inside
the advice with thisJoinPoint.getThis() (surprised, this does not return
the
advice itself, as it does for "call()" or "execution()").
But how can I get the exception instance and the method signature?
Harry
|
|
|
Re: Catch Exception instance in advice for handler pointcut [message #585874 is a reply to message #46225] |
Mon, 17 January 2005 02:38  |
Eclipse User |
|
|
|
On Mon, 17 Jan 2005 02:45:22 +0000 (UTC), harry sheng wrote:
> I can only use before() advice for "handler()" pointcut. "this()" or
> "target()"
> cannot be used together with "handler()".
Correct.
> I can get the object instance
> inside
> the advice with thisJoinPoint.getThis() (surprised, this does not return
> the
> advice itself, as it does for "call()" or "execution()").
It actually never does. (Read the docs!) This is *only* the case when the
advice itself *is* the caller/executiong object.
> But how can I get the exception instance and the method signature?
Hmmm this is an interesting question then...
Ok, I read up on that and it seems that the Exception can be exposed by
pointcut HandledException(Exception ex):
handler(NullPointerException)&&args(ex);
The method signature can certainly be retrieved by
thisJoinPointStaticPart.getSignature() or
thisEnclosingJoinPointStaticPart.getSignature()
Eric
--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
Arithmetische Kodierung - eine umfassende Einführung
http://bodden.de/studies/publications/pub_ac_de/
|
|
|
Re: Catch Exception instance in advice for handler pointcut [message #585919 is a reply to message #46260] |
Mon, 17 January 2005 12:05  |
Eclipse User |
|
|
|
>> I can get the object instance
>> inside
>> the advice with thisJoinPoint.getThis() (surprised, this does not return
>> the
>> advice itself, as it does for "call()" or "execution()").
> It actually never does. (Read the docs!) This is *only* the case when the
> advice itself *is* the caller/executiong object.
thisJoinPoint.getTarget() always returns "null" no matter where the "catch
(MyException ex)" block is.
thisJoinPoint.getThis() returns "null" if the "catch (MyException ex)"
block is in the "public static void main(String[] arg)" method, otherwise
it returns the object instance.
>> But how can I get the exception instance and the method signature?
> Hmmm this is an interesting question then...
> Ok, I read up on that and it seems that the Exception can be exposed by
> pointcut HandledException(Exception ex):
> handler(NullPointerException)&&args(ex);
Thanks very much, Eric. This worked.
> The method signature can certainly be retrieved by
> thisJoinPointStaticPart.getSignature() or
> thisEnclosingJoinPointStaticPart.getSignature()
Have to use thisEnclosingJoinPointStaticPart to get the method signature.
So far so good, as long as I can retrieve it.
|
|
|
|
Powered by
FUDForum. Page generated in 0.48697 seconds