After-Throwing Advices Example
Examples You can find examples of after-throwing advice in the Aspect.java file. The following advice signature: public void afterThrowing(@Thrown Throwable thrown) Is the simplest you can write, since the @Thrown-annotated parameter is mandatory. But you can also include any other annotated parameter (except @Return, which is exclusive of after advices). The following advice signature is valid to intercept a method execution throwing a POJOException exception: public void afterThrowingJoinPoint(@JoinPoint MethodExecution methodExecution, @Thrown POJOException thrown) Notice that you can declare the annotated parameters in any order you wish. If the method being intercepted receives an String argument, and you want to intercept that method throwing RuntimeExceptions, these after-throwing signatures are also valid: public void afterThrowingArg(@Thrown RuntimeException thrown, @Arg String argument) public void afterThrowingJoinPointArg(@Thrown NullPointerException thrown, @JoinPoint MethodExecution methodExecution, @Arg String argument) Note that the first one receives a RuntimeException as @Thrown-annotated parameter. Thus, this advice is going to be invoked only when the intercepted method throws a RuntimeException. The second advice is more specific regarding this parameter, and will be invoked only when the intercepted method throws a NullPointerException.