Java’s CompletableFuture and typed exception handling
March 26th, 2018With version 8, Java finally jumped on the asynchronous programming bandwagon with its own Promise-Oriented programming model, implemented by the CompletableFuture
class and a set of interfaces and implementations it uses. The model is generally useful and not as horribly complicated as we sometimes get in the Java foundation class library1, and it lends itself to fluent programming much better than the comparable model from fluent API proponent Vert.x project.
The Problem
One thing that most asynchronous computing models suffer from – and Java’s CompletableFuture
is no exception – is the loss of typed exception handling. While CompletableFuture.exceptionally()
is a good model that does not introduce a lot of boilerplate2, you do lose the ability of the try..catch..finally
syntax to effortlessly ignore exceptions you are not ready to handle and just letting them propagate up the stack. Read the rest of this entry »