Java 在spring boot中的@ExceptionHandler中引发另一个异常不起作用
我有一个CustomException,我用Java 在spring boot中的@ExceptionHandler中引发另一个异常不起作用,java,spring-boot,exception,Java,Spring Boot,Exception,我有一个CustomException,我用@ExceptionHandler(CustomException.class) 在一种情况下,我将得到一个无效格式异常,因此我需要从那里重新跳转到我的CustomException。我尝试抛出异常,但它没有按预期工作 @ExceptionHandler(InvalidFormatException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public Error inval
@ExceptionHandler(CustomException.class)
在一种情况下,我将得到一个无效格式异常
,因此我需要从那里重新跳转到我的CustomException。我尝试抛出异常,但它没有按预期工作
@ExceptionHandler(InvalidFormatException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Error invalidFormat(InvalidFormatException e) throws CustomException {
if (logicToValidate()) {
throw new CustomException();
} else {
return new Error(BAD_REQUEST.name(), e.getMessage(), ErrorLevel.ERROR);
}
}
@ExceptionHandler(CustomException.class)
public Error customException(CustomException e) {
...
}
经过研究,我发现了这条线索。所以现在不可能在spring boot中重新显示异常。相反,如果有的话,我们可以尝试其他的策略