This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Intercepting specific Exception subclass

Dec 1st, 2011, 01:38 PM

I'm trying to configure Spring so that it executes advice when a specific exception subclass (MyTestException) is thrown:

Code:

public class MyTestExceptionInterceptor implements ThrowsAdvice
{
public void afterThrowing(Method method, Object[] args, Object target, Exception exc)
{
// I want this to get executed every time a MyTestException is thrown,
// regardless of the package/class/method that is throwing it.
}
}

I have a feeling that I should be using the target pointcut specifier (instead of "execution") since - according to the Spring docs (Ch 6) - it seems as though target allows me to specify the type of exception to match against, but I'm not sure if that's wrong, or what my "pointcut" attribute needs to look like.

I would greatly prefer to keep the AOP config done in XML (as opposed to Java/annotations, but I could probably translate an annotation-based solution into XML if need be.