i have this method:
default <U> CompletableFuture<U> submit(Supplier<U> supplier) {
return CompletableFuture.supplyAsync(supplier, .....getThreadPool());
}
it is used widely by different classes, but currently if a computation fails there is no default logging. My first approach is:
.exceptionally(throwable ->
.....handleThrowable(throwable, runnable);
)
But this method is intended for recovery, since i have to return something. What if i just want to log it?
This will handle the exception and return the original result, so the downstream code will also have a chance to do something with the exception. Is that what you intend?
default <U> CompletableFuture<U> submit(Supplier<U> supplier) {
return CompletableFuture.supplyAsync(supplier, ....)
.whenComplete((u, ex) -> {
if (ex != null) {
handleThrowable(ex);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With