java - 在 Spring Boot 中在 @ExceptionHandler 中抛出另一个异常不起作用
问题描述
我有一个我处理的 CustomException@ExceptionHandler(CustomException.class)
在一种情况下,我会InvalidFormatException
从那里得到一个所以我需要重新抛出我的 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) {
...
}
解决方案
在做了一些研究之后,我发现了这个线程https://github.com/spring-projects/spring-framework/issues/18299。所以现在不可能在 spring boot 中重新抛出异常。相反,我们可以尝试替代策略,如果有的话。
推荐阅读
- c# - 删除函数从数据库中删除表值,但不从 BLAZOR 中的 HTML 表中删除
- python - Matplotlib 在将 kivy 应用程序转换为 iOS 时未通过工具链命令安装;kivymd 也有问题
- pandas - 如何使用 XML 电子表格创建 DataFrame?
- python - ValueError:没有为任何变量张量流keras提供梯度
- android-jetpack-compose - Jetpack Compose collectAsState() 不适用于 Flow combine()
- c# - linux容器中的活动目录身份验证问题
- spring-boot - Spring boot 和 TLS1.3 密钥库不适用于 Docker 和其他计算机
- django - Django in_bulk() 使用 distinct() 引发错误
- python - Show completion list when qlineEdit textChanged
- ios - Could not cast value of type 'FlutterViewController' to 'UINavigationController'