[jboss-user] [JBoss AOP] - Re: Can i have interceptor on throw exception?

stale.pedersen@jboss.org do-not-reply at jboss.com
Tue Apr 29 04:55:38 EDT 2008


yes, you can just add an interceptor that catches exceptions. i made an ejb3 interceptor for a client some time ago that was just a "wrapper" for exceptions. eg, if an exception was thrown the interceptor would catch it, parse it, and then throw a checked in-house exception ( we didnt want the client to be given ejb3 exceptions).
here is a sample of it:

  | import javax.interceptor.AroundInvoke;
  | import javax.interceptor.InvocationContext;
  | 
  | public class FooSystemExceptionInterceptor 
  | {   
  |    @AroundInvoke
  |    public Object intercept(InvocationContext ctx) throws Exception
  |    {
  |       long start = System.currentTimeMillis();
  |       try
  |       {
  |          return ctx.proceed();
  |       }
  |       catch(RuntimeException re) 
  |       {
  |          System.out.println("Original Exception:");
  |          re.printStackTrace();
  |          throw handleException(re);
  |       }
  |       finally 
  |       {
  |          System.out.println("Facade call "+ctx.getMethod().getName()+" took: "+(System.currentTimeMillis()-start));
  |       }
  |    }
  |    
  |    private FooSystemException handleException(RuntimeException e) 
  |    {
  |       ....       
  |       return mySystemException;
  |    }
  | 
  | }
then you just add this interceptor to the beans you want to intercept. let me know if this solves (or not) your problem :)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4147451#4147451

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4147451



More information about the jboss-user mailing list