After Throwing Advice
Details as well as Examples covering After Throwing Advice.
Sample Example
Scenario 1: Capturing exception details via AOP
package org.example.logging;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
@Component
public class LoggingAspect {
private static final String AFTER_THROWING_POINTCUT ="execution(* org.example.controller.*.*(..))";
@AfterThrowing(value = AFTER_THROWING_POINTCUT, throwing = "exception")
public void logsErrors(JoinPoint joinPoint, Throwable exception){
// Log the controller name
log.info("AfterThrowing - {}", joinPoint.getSignature().getName());
// Log the exception message
log.info("AfterThrowing - {}", exception.getMessage());
}
}

Last updated