Handling exceptions of an asynchronous task via exceptionally()

User problem: Compute the total of an order. If something goes wrong, then throw an IllegalStateException.

The following screenshots exemplify how exceptions are propagated in an asynchronous pipeline; the code in rectangles is not executed when an exception occurs at the point:

The following screenshot shows the exceptions in thenApply() and thenAccept():

So, in supplyAsync(), if an exception occurs, then none of the following callbacks will be called. Moreover, the future will ...

Get Java Coding Problems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.