Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Exception Handling PointsCuts/Advices

Hi Sudhakar

I get this as a digest so I may have missed something, but I think the execution pointcut you have done will only match if the exception is actually listed in the method throws clause.

To get around this you could either add the exceptions to the throws clause (probably not desirable since they are unchecked exceptions) or write a pointcut to more specifically pick out the methods that you actually want to apply the exception handling to.

Regards Chris

Message: 1
Date: Tue, 30 Aug 2005 11:07:28 -0700
From: "Sudhakar Ramakrishnan" <sramakrishnan@xxxxxxxx>
Subject: [aspectj-users] Exception Handling PointsCuts/Advices
To: <aspectj-users@xxxxxxxxxxx>
Message-ID: <54808B311D66EB4E9CF4647B0DE707C2A13D55@xxxxxxxxxxxxxxxxx>
Content-Type: text/plain;	charset="US-ASCII"

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

Attention:
This email may contain information intended for the sole use of
the original recipient. Please respect this when sharing or
disclosing this email's contents with any third party. If you
believe you have received this email in error, please delete it
and notify the sender or postmaster@xxxxxxxxxxxxxxxxxxxxx as
soon as possible. The content of this email does not necessarily
reflect the views of SolNet Solutions Ltd.



Back to the top