exceptionally
The CompletableFuture method that supplies a fallback result when an earlier stage has failed.
In more detail
It receives the failure and returns a replacement value, turning a failed chain back into a successful one. Keep the original cause in logs when you recover this way.
Example
.exceptionally(ex -> "fallback")Related terms
- CompletableFuture — A Future that can be completed later and chained, letting you describe asynchronous steps such as transform, combine and recover without nesting callbacks.
- exception chaining — Linking a new exception to the one that caused it, so the higher-level failure still carries the original error and its stack trace.
Taught in
- Async With CompletableFuture — Modern Java: Virtual Threads & High-Throughput Services