May 2015
Intermediate to advanced
234 pages
4h 18m
English
An after-throwing advice executes some extra code when an exception is thrown during the execution of the target method. In this recipe, we will just log the exception.
We will use the aspect class defined in the Creating a Spring AOP aspect class recipe.
Here are the steps for logging an exception using an after-throwing advice:
@AfterThrowing. Make it take a JoinPoint object and an Exception object as arguments:@AfterThrowing(pointcut="execution(* com.spring_cookbook.controllers.*.*(..))", throwing="exception")
public void logException(JoinPoint joinPoint, Exception exception) {
...
}Read now
Unlock full access