Skip to main content



      Home
Home » Language IDEs » AspectJ » Catch Exception instance in advice for handler pointcut
Catch Exception instance in advice for handler pointcut [message #46139] Fri, 14 January 2005 11:33 Go to next message
Eclipse UserFriend
Hi,

Is it possible to catch the Exception instance in advice for handler
pointcut?
The handler pointcut signature does not have the method info anymore?

Harry Sheng
Re: Catch Exception instance in advice for handler pointcut [message #46197 is a reply to message #46139] Sat, 15 January 2005 15:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: newsserver_mails.bodden.de

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
}

--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
Active Desktop Wallpaper Changer: That's what it is...
http://bodden.de/projects/wpchanger/
Re: Catch Exception instance in advice for handler pointcut [message #46225 is a reply to message #46197] Sun, 16 January 2005 21:45 Go to previous messageGo to next message
Eclipse UserFriend
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 #46260 is a reply to message #46225] Mon, 17 January 2005 02:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: newsserver_mails.bodden.de

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 #46374 is a reply to message #46260] Mon, 17 January 2005 12:05 Go to previous messageGo to next message
Eclipse UserFriend
>> 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.
Re: Catch Exception instance in advice for handler pointcut [message #46432 is a reply to message #46374] Mon, 17 January 2005 15:07 Go to previous message
Eclipse UserFriend
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 #585847 is a reply to message #46139] Sat, 15 January 2005 15:44 Go to previous message
Eclipse UserFriend
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
}

--
Eric Bodden, ICQ: 12656220, http://www.bodden.de, PGP: BB465582
Active Desktop Wallpaper Changer: That's what it is...
http://bodden.de/projects/wpchanger/
Re: Catch Exception instance in advice for handler pointcut [message #585859 is a reply to message #46197] Sun, 16 January 2005 21:45 Go to previous message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
>> 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.
Re: Catch Exception instance in advice for handler pointcut [message #585946 is a reply to message #46374] Mon, 17 January 2005 15:07 Go to previous message
Eclipse UserFriend
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/
Previous Topic:Catch Exception instance in advice for handler pointcut
Next Topic:PointCut and Advice to "new" object
Goto Forum:
  


Current Time: Tue Jun 17 07:02:50 EDT 2025

Powered by FUDForum. Page generated in 0.48697 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top