How to handle uncaught exceptions from CompletableFuture.runAsync

Our application has some code that runs asynchronously that is failing. Like this:


() -> { throw new RuntimeException("bad"); },



We want default exception handling code that can catch these errors, in case specific uses forget to handle exceptions (this came from a production bug).

This is apparently tricky. The answer given in Handling exceptions from Java ExecutorService tasks does not work.

It relies on the task being a Future and then calling get() on it, resulting in the exception being thrown again. But this is not the case for runAsync code.

runAsync creates a...

Read More »

By: StackOverFlow - Thursday, 8 November

Related Posts