Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Excluding Particular Joinpoints


You may add a thread local variable boolean isNormalException and expose public static getter/setter for the variable. If a developer knew that an exception handler is normal, do the following :

try {
...
} catch (Throwable ex) {
        // do not want any trace / log at this point
        setNormalException(true);
        ...
}

The advice can be:

after() : handler(Throwable+) {
         if(getNormalException() == false) {
                // do some logging
         }
         setNormalException(false);
}

There are two concerns with this approach:
1. another crosscutting has been introduced (setNormalException in exception handler).
2. dynamic checking should be avoid as much as possible.

I agree that annotation could be the best way to handle this. But if it does not work, the above proposal may work for you.

Bo
----------------------------------------------------------
 Dr. Bo Yi
 WebSphere Development & Testing
 IBM Toronto Lab
 A2-713/Q2Z/8200/MKM
 8200 Warden Ave. Markham ONT. L6G 1C7
 Phone: 905-413-4819
 Tie Line: 969-4819
 E-Mail: boyi@xxxxxxxxxx



"Tobias Dunn-Krahn" <tdunn-krahn@xxxxxxxxxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

11/30/2005 05:03 PM

Please respond to
aspectj-users

To
<gregor@xxxxxxxxx>, <aspectj-users@xxxxxxxxxxx>
cc
Subject
RE: [aspectj-users] Excluding Particular Joinpoints





Gregor and Ron,
 
Thanks for your suggestions.  Unfortunately in my case, I can’t determine from just the Throwable whether or not it should be logged.  For example, a FooBarException should be logged in some cases but not others, depending on the surrounding application logic.  Really the only way to determine this is a decision on the part of developer, which is why I was experimenting with annotations.
 
Perhaps I could use thisJoinPoint in combination with a naming convention for the throwable, i.e. any throwable named “expectedThrowable” would not be logged.  It would be nice if I could do something more explicit (like an annotation) but perhaps it’s not possible.  Please let me know if I’ve misunderstood something about your suggestions.
 
Thanks,
Tobias
 



From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Gregor Kiczales
Sent:
Wednesday, November 30, 2005 1:26 PM
To:
aspectj-users@xxxxxxxxxxx
Subject:
RE: [aspectj-users] Excluding Particular Joinpoints

 



From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tobias Dunn-Krahn
 
I am using AspectJ in a project to log all handled exceptions.  In general this is what I want, but in a small number of cases such exceptions are “expected” and I do not wish to log them.
 
aspect FooBarExceptionLoggingStrategy {
 
  before(Throwable t): handler(Throwable) && args(t) {
    if( shouldLog(t) )
       log(t);
  }
 
  private boolean shouldLog(Throwable t) {
    <<test whatever needs testing here>>
  }
 
  private void log(Throwable t) {
    ...
  }
}
 
The point being that you can test the exception in any way you want before logging it.
You could also pass thisJoinPoint or thisJoinPointStaticPart. If you want, you could
move shouldLog into the actual pointcut, using if(shouldLog(t)).
 
 
 



From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tobias Dunn-Krahn
Sent:
Wednesday, November 30, 2005 11:42 AM
To:
aspectj-users@xxxxxxxxxxx
Subject:
[aspectj-users] Excluding Particular Joinpoints

Hello All,
 
I am using AspectJ in a project to log all handled exceptions.  In general this is what I want, but in a small number of cases such exceptions are “expected” and I do not wish to log them.  My pointcut definition is currently very simple; it matches all exception handlers except those that handle SocketTimeoutExceptions:
 
  pointcut exceptionHandlers(Throwable t) : handler(Throwable+) && (args(t)
      && !args(java.net.SocketTimeoutException));
 
However, now I need to exclude matching of particular exception handlers that are not distinguishable by type.  I tried creating a custom annotation with target type LOCAL_VARIABLE and using this annotation to decorate the exception, but unfortunately annotations of this type are not retained for runtime (and are therefore inaccessible).  Does anyone have any suggestions?
 
Thanks in advance,
Tobias
 _______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top