Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Using Exception Handlers in AspectJ

There are some examples using handler() in the sample
code linked off the documentation page of the web site.

The semantics appendix of the programming guide is the
best reference.  handler() is also subject to some
rare implementation limitations described in
not-yet-published updates to the programming guide
in CVS, which I've copied below for your convenience.

Wes

-------------------------------
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/sample-code.html

-------------------------------
The Handler join point

The end of exception handlers cannot reliably be found in Java bytecode. Instead of removing the handler join point entirely, the current AspectJ compiler restricts what can be done with the handler join point:

    * After and around advice cannot apply to handler join points.
    * The control flow of a handler join point cannot be detected.

The first of these is relatively straightforward. If any piece of after advice (returning, throwing, or "finally") would normally apply to a handler join point, it will not in code output by the current AspectJ compiler. A compiler warning is generated whenever this is detected to be the case. Before advice is allowed.

The second is that the control flow of a handler join point is not picked out. For example, the following pointcut

  cflow(call(void foo()) || handler(java.io.IOException))

will capture all join points in the control flow of a call to void foo(), but it will not capture those in the control flow of an IOException handler. It is equivalent to cflow(call(void foo())). In general, cflow(handler(Type)) will pick out no join points.

This does not restrict programs from placing before advice on handlers inside other control flows. This advice, for example, is perfectly fine:

  before(): handler(java.io.IOException) && cflow(void parse()) {
      System.out.println("about to handle an exception while parsing");
  }

A source-code implementation of AspectJ (such as AspectJ 1.0.6) is able to detect the endpoint of a handler join point, and as such will likely have fewer such restrictions.



Bellamy, Scot wrote:

I am new to AspectJ, and new to AOP in general.

I have been reading through the documentation, trying to understand how the Exception Handler works.  I tried looking in the Archive but it requires a userid and password (and I didn't know what that is).

Can someone send me a brief explanation and sample for how to use the handler pointcut?  Also, if you know how I can get into the archive, that would be great too!

Thanks,
Scot.



Scot A. Bellamy			Cardinal Health
Technical Specialist			7000 Cardinal Place
Application Architect		Dublin, OH  43017
Corporate Information Technology	614.757.7284  tel
				614.652.4213  fax
					scot.bellamy@xxxxxxxxxxxx
				www.cardinal.com


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top