Errors in async code
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
propagate and handle failures.
Planned topics
- An exception completes the stage exceptionally; dependent stages are skipped and carry it forward.
exceptionally(fn): recover with a fallback value.handle((v, ex) -> ...): see both result and error;whenCompleteobserves without changing.join()throwsCompletionException;get()throwsExecutionException; the cause is wrapped.- An unobserved failed future loses the error silently; always attach handling or read it.
Draft outline details
Demonstration
CompletableFuture<List<Review>> r = reviewsF.exceptionally(ex -> List.of()); // degrade gracefullyCheck your understanding
What does a downstream thenApply do when its source failed?
Show answer
It is skipped and the failure propagates.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.