Announcement Announcement Module
Collapse
No announcement yet.
exception conversion Aspect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • exception conversion Aspect

    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:

    Code:
    <bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
    and have defined my aspect thus:

    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;
        }
      }
    }
    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?

    Thanks in advance,
    DM
    Last edited by domurtag; Mar 4th, 2008, 08:21 AM.
Working...
X