如何在@Retryable
方法的同一块中捕获两个不同的异常(例如来自.lang
和.io
包(。一个是返回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 = { IllegalAccessException.class, IOException.class },
maxAttempts = 3,
backoff = @Backoff(delay = 3000))
public String getInfo() {
// some code
}