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

stale.pedersen@jboss.org do-not-reply at jboss.com
Wed Apr 30 08:49:09 EDT 2008


with aop 1.5 you have to add a around pointcut to every method in your code that can throw an exception. the interceptor will be something like:
public class CatchExceptionInterceptor implements Interceptor
  | {
  |   public String getName() { return "CatchExceptionInterceptor"; }
  |   
  |   public Object invoke(Invocation inv) throws Throwable
  |   {
  |     try
  |     {
  |        return inv.invokeNext();
  |     }
  |     catch(Exception e)
  |     {
  |      logExceptionHere();
  |      return e;
  |     }
  |     finally
  |     {
  |      blabla
  |      }
  |    }
  | } 
and then you need to add pointcuts that binds this interceptor to all you methods/construcors (i guess thats all that can throw an exception) eg:
<bind pointcut="execution(* * org.foo.*->*(..))">
  |   <interceptor class="CatchExceptionInterceptor"/>
  | </bind>
  | <bind pointcut="whatever_that_fits...">
  |   <interceptor class="CatchExceptionInterceptor"/>
  | </bind>
- i wouldnt recommend this for other than testing though :)

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

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



More information about the jboss-user mailing list