[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| [aspectj-users] Exception handling framework | 
Has anyone ever thought about designing an AOP framework for Exception 
Handling. Some investigations have been done in [1], but I was wondering 
if it could be possible to build a complete Exception handling framework 
in AspectJ, and how one would do that.
I could define an abstract pointcut for methods that "could throw an 
error", and than put different "after throwing..." advice on that 
pointcut. For example one piece of after advice for every possible error 
in Java (that's a lot of work, I know). Those pieces of advice could call 
default handle methods for all the adviced Exceptions. A user of this 
framework would that have to write a sub-aspect, defining the abstract 
pointcut (for example every method not in the cflow of the aspect) and may 
also override some methods to change the default behaviour.
A little example from the abstract aspect:
after () throwing (RuntimeException): possibleExceptionThrowingMethod () {
	handleRuntimeException (e, thisJoinPoint);
}
protected void handleIOException (IOException e, JoinPoint jp) {
	//do something default
}
//analoge advice and methods for al other exceptions in java
I pass the thisJoinPoint as argument, for the methods to be able to do 
something usefull.
If users have there own exceptions, they can ofcourse be added to the 
sub-aspect the user has to write.
This approach solves the crosscutting nature of normal Exception handling 
if the same Exceptions (with the same Exception handling) appear in 
different places in the application. It is also reusable, and it easily 
supports the possibility to change the behaviour in exception handling 
afterwards. You just have to edit code in one place.
I do have one remaining problem: every method in the application that 
could throw an exception should have a "throws ...Exception" in its 
declaration, or there should be a try-catch block. The catch should than 
be left empty, as the handling is done by the aspect. I do not see any 
sollution to this problem.
I'm planning to test my approach in some more realistic examples. Any 
comments are very welcome ofcourse. It's al just a first idea.
Jan Van Besien
[1]
"A Study on Exception Detection and Handling Using Aspect-Oriented 
Programming" Martin Lippert and Cristina Lopes. In Proc. of the 22nd 
International Conference of Software Engineering (ICSE'2000), Limmerick, 
Ireland. IEEE Computer Society. June 2000.