Results 1 to 1 of 1

Thread: exception conversion Aspect

  1. #1
    Join Date
    Oct 2006
    Posts
    156

    Default 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 at 08:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •