我们如何在.lang
方法的同一块中捕获两个不同的异常(例如.io
和@Retryable
包中的异常)。一种是我们返回IOException
,另一种是我们重试该方法。
@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();
}
}
最佳答案
您可以使用批注的 include
参数来处理多个各种异常:
@Retryable(
include = { java.lang.IllegalAccessException.class, java.io.IOException.class },
maxAttempts = 3,
backoff = @Backoff(delay = 3000))