[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Exception Handling PointsCuts/Advices
|
How would one go about define pointcuts and advices for something like
this?
Class A throws a number of different types of unchecked exceptions. I
want to define a pointcut that captures these execution join points,
catch the unchecked exception, do some processing with the exception
object, and possibly rethrow the exception as a custom exception. If
anyone has samples for this it would be great.
More details:
Let's say we have
Class A:
public void createAccount(String type) {
if (type.equals("aaa")) {
throw new NullPointerException("aaa");
} else if (type.equals("bbb")) {
throw new BufferOverflowException();
} else if (type.equals("cccc")) {
throw new
MissingResourceException("missing","missing","missing");
}
}
We create Class A objects in Class B.
Class B:
A obj = new A();
Try {
A.createAccount();
} catch (CustomException e) {
// hoping aspectj has rethrow certain unchecked exceptions as
customexceptions
}
Essentially, I want to capture some of those unchecked exceptions and
cast it into a customexception. If there are checked I will convert them
to soft exceptions and convert them if needed.
I am starting with something like this and want some help since I am new
to AspectJ syntax.
public aspect ExceptionHandler {
pointcut customException():
(execution (* *.*(..) throws NullPointerException)
|| execution (* *.*(..) throws BufferOverflowException)
|| execution (* *.*(..) throws
MissingResourceException))
&& within (A);
// I guess I need after throwing
after() : customException() {
//do some processing with the exception object, like logging etc
throw new CustomException();
}
}
-
Sudhakar Ramakrishnan