Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Retry - Exception problem and retries

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();
    }   
}
like image 351
Med Avatar asked Oct 21 '25 11:10

Med


1 Answers

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
}
like image 140
Nikolas Charalambidis Avatar answered Oct 24 '25 00:10

Nikolas Charalambidis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!