Member-only story
Java Concurrency Uncovered — Part 10 : CompletableFuture: Handling Exceptions
Learn how to recover from failures, process both success and failure outcomes, and run post-completion actions using exceptionally(), handle(), and whenComplete().
Everything about an async pipeline works fine until one part of it doesn’t. A payment gateway times out mid-authorization. A downstream service goes down without warning. In a synchronous world, a try-catch around the whole operation might handle it — but in an asynchronous chain, the failure can surface several stages deep, on a thread you never touched, with nowhere obvious to go.
This is the gap CompletableFuture’s exception-handling methods address. exceptionally(), handle(), and whenComplete() provide three ways to respond to failures — recover with a fallback, process success and failure together, or react after completion without changing the outcome.
CompletableFuture — Exception Handling
Asynchronous tasks can fail because of network issues, service outages, invalid input, or unexpected runtime errors.
CompletableFuture provides several ways to handle these failures:
exceptionally()—…








