【发布时间】:2019-04-13 18:37:54
【问题描述】:
我有一个 Spring Boot 应用程序,我在那里处理异常。我现在有两种异常处理方法:
@ControllerAdvice
@RestController
public class MyExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public final BaseResponse<GenericException> handleGenericExceptions(Exception ex, HttpServletRequest request) {
....
return response;
}
@ExceptionHandler(MyCustomException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public final BaseResponse<MyCustomException> handleMyCustomException(MyCustomException ex, HttpServletRequest request) {
....
return response;
}
}
在某些时候,我抛出了一个 MyCustomException 异常,但是当我调试时,我发现它是由 handleGenericExceptions 方法处理的。如果我删除了handleGenericExceptions 方法,那么它由handleMyCustomException 消息处理。
我希望 MyCustomException 由 handleMyCustomException 方法处理,所有其他异常由 handleGenericExceptions 方法处理。 MyCustomException 类扩展 Throwable。这里有什么问题?
谢谢。
【问题讨论】:
标签: spring spring-boot exception