【发布时间】:2023-03-30 04:32:01
【问题描述】:
我在 controllerAdvice 中有多个 ExceptionHandler。一个用于 TimeoutException,另一个用于 Exception 类。
当我抛出新的 TimeoutException 时,它会在异常处理程序中而不是在 TimeoutException 处理程序中被捕获
下面是代码:
@ControllerAdvice
public class CoreControllerAdvice {
@ExceptionHandler(value = { Exception.class })
@ResponseBody
public ResponseEntity<ErrorResponse> handleException(Exception ex) {
log.info("handleException", ex);
}
@ExceptionHandler(value = { TimeoutException.class })
@ResponseBody
public ResponseEntity<ErrorResponse> handleTimeoutException(Exception ex) {
log.info("handleTimeoutException", ex);
}
}
我抛出异常
throw new TimeoutException("test");
有人可以帮忙吗,为什么它没有被 TimeoutException Handler 捕获
谢谢,
【问题讨论】:
标签: spring spring-boot timeoutexception