Q 31
What is exception handling in retry logic?
Answer
Retry logic should retry only failures that are transient and potentially recoverable, while permanent validation or business failures should normally fail immediately.
Explanation
Retries should also have limits, delays, and preferably backoff. Blindly retrying every exception can increase load and make an outage worse.
Code Example
Java
for (int attempt = 1; attempt <= 3; attempt++) {
try {
externalService.call();
break;
} catch (TransientServiceException e) {
if (attempt == 3) {
throw e;
}
sleepBeforeRetry(attempt);
}
}
Reference:
Java Exception Handling