英文:
Spring Retry - Exception problem and retries
问题
@Retryable(value = {IOException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000))
public String getInfo() {
try {
// 在这里放置可能会引发 IOException 的执行代码
} catch (IOException ex) {
// 在这里捕获 IOException 并重新抛出
throw ex;
} catch (Exception ex) {
// 在这里捕获其他 Exception
throw new RuntimeException(ex);
}
}
英文:
How can we catch two different exceptions (ex. from .lang
and .io
packages) in the same block of @Retryable
method. One, we return an IOException
and the other we retry the method.
@Retryable(value = {Exception.calss } ,maxAttempts = 3, backoff = @Backoff(delay = 3000))
public String getInfo() {
try {
//here we have an executive code that may have an IOException
} catch(Exception ex) {
//And here i would catch the Exception
throw new Exception();
}
}
答案1
得分: 9
你可以使用注解的 include
参数来处理多种不同的异常:
@Retryable(
include = { IllegalAccessException.class, IOException.class },
maxAttempts = 3,
backoff = @Backoff(delay = 3000))
public String getInfo() {
// 一些代码
}
英文:
You can use the include
parameter of the annotation to handle multiple various exceptions:
@Retryable(
include = { IllegalAccessException.class, IOException.class },
maxAttempts = 3,
backoff = @Backoff(delay = 3000))
public String getInfo() {
// some code
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论