4

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();
    }   
}
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
Med
  • 45
  • 1
  • 8

1 Answers1

9

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
}
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183