如何解决尽管方法声明中声明的已检查异常
编辑:我仔细阅读了链接的主题 (Getting UndeclaredThrowableException instead of my own exception),但它没有回答我的问题 - 该票建议在我已经做过的拦截方法中声明已检查的异常。
我正在尝试使用 Spring Retry 机制并希望在解析方法中抛出我的自定义检查异常,但它因 UndeclaredThrowableException 而失败。这是我所做的:
- 我已经声明了我的自定义 RuntimeException(这表明我需要重试):
public class RestCallRetryException extends RuntimeException
- 我在执行以下方法时抛出此运行时异常:
@Retryable(value = RestCallRetryException.class,maxAttempts = 2) InquiryResponse postInquiry(InquiryRequest inquiryRequest) throws RestCallException;
- 我已经声明了重试方法来处理它:
@Recover InquiryResponse recover(RestCallRetryException e) throws RestCallException;
- 如您所见,我还有 RestCallException,它是在 recovery 中抛出的已检查异常:
public class RestCallException extends Exception
我在recover(RestCallRetryException e) 的实现中抛出RestCallException 并得到UndeclaredThrowableException。我不明白为什么会发生这种情况。如果我没有声明用@Retryable (postInquiry) 标记的方法会抛出 RestCallException,我会理解情况会是这样——但这一切都如您在我的代码片段中看到的那样声明。我在这里错过了什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。