Exception Policy¶
Controls what happens when recovery finds no valid stored entry — re-throw the original exception, return null, or run your own logic.
Three Strategies¶
| Strategy | Behaviour | Config value |
|---|---|---|
RETHROW | Re-throws the original upstream exception | rethrow (default) |
NEVER_THROW | Returns null (or RecoveredPayloadHandler result) | never_throw |
CUSTOM | Your own MethodExceptionPolicy bean | custom |
RETHROW (Default)¶
The upstream exception propagates to the caller when no stored entry is found or all entries are expired.
Use RETHROW when callers must know that the upstream is unavailable and cannot gracefully handle a null response.
NEVER_THROW¶
Returns null (or the value from RecoveredPayloadHandler) instead of propagating the exception. The caller receives null on no recovery.
Combine with RecoveredPayloadHandler
Pair never_throw with a RecoveredPayloadHandler to return an empty list, a default object, or any safe fallback instead of null. See Recovered Payload Handler.
CUSTOM — Implement MethodExceptionPolicy¶
@Component
public class LogAndNeverThrowPolicy implements MethodExceptionPolicy {
@Override
public void handle(MethodExceptionContext context) {
log.warn("Failover: no recovery for '{}', suppressing exception",
context.getFailover().name(), context.getCause());
// returning without throwing means the caller gets null
}
}
MethodExceptionContext carries: - getFailover() — the @Failover annotation metadata - getArgs() — the original method arguments - getCause() — the upstream exception - getClazz() — the return type class
Next Steps¶
- Recovered Payload Handler — return a safe default on null recovery
- Properties Reference —
failover.exception-policy