Hi,
I'm trying to define an aspect that will convert all exceptions thrown within the package "com.example" to runtime exceptions. I've added the following bean definition to my Spring config:
and have defined my aspect thus:Code:<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
This all seems to be working fine, but I've noticed in some AOP examples, that a JoinPoint parameter is passed to the advice method, which would provide (in the example above) access to the class name, parameter values, etc. of the method that threw the exception. Is this JoinPoint parameter available in all types of advice, and if so, how do I ensure that it is passed to toRuntimeException() above?Code:@Aspect public class ExceptionInterceptor { @AfterThrowing(pointcut="execution(* com.example.*.*(..))", throwing="t") public void toRuntimeException(Throwable t) { if (t instanceof KnownException) { throw (KnownException) t; } else { ServiceException se = new ServiceException(t.getMessage()); se.setStackTrace(t.getStackTrace()); throw se; } } }
Thanks in advance,
DM


Reply With Quote