aspectj - handling a specific exception type -
i've defined 2 afterthrowing advices handle exceptions same pointcut.
@afterthrowing(pointcut="...", throwing="ex") public void method1(exception ex) {} @afterthrowing(pointcut="...", throwing="ex") public void method2(gatewayexception ex) {}
is there way me prevent generic method1 being executed if exception gatewayexception?
any ideas appreciated
c
it easiest check instance of exception inside advice body , return if it's of more specific exception type:
@afterthrowing(pointcut="...", throwing="ex") public void method1(exception ex) { if (ex instanceof gatewayexception) { return; } // handle more generic exception case } @afterthrowing(pointcut="...", throwing="ex") public void method2(gatewayexception ex) { // handle more specific gatewayexception }
i know expected solution based on aspectj language construct, thing is, there's no such construct.
Comments
Post a Comment