Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

whenComplete overwrites original exception (it shouldn't) #9

Open
vsilaev opened this issue Mar 16, 2018 · 0 comments
Open

whenComplete overwrites original exception (it shouldn't) #9

vsilaev opened this issue Mar 16, 2018 · 0 comments

Comments

@vsilaev
Copy link
Contributor

vsilaev commented Mar 16, 2018

Here is a code snippet (from SimpleCompletionStage):

                failure -> {
                    try {
                        action.accept(null, failure);
                        handleFailure(nextStage, failure);
                    } catch (Throwable e) {
                        handleFailure(nextStage, e);
                    }
                }

However, for CompletableFuture it's different:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#whenComplete-java.util.function.BiConsumer-

i.e. original exception is not overwritten for next stages.

So probably it makes sense to use handleFailure(nextStage, failure); to propagate original exception (as CompletableFuture does). Personally, in my own library I've added exception from handler as suppressed exception to failure and forward failure to next stages.

By the way, handle family of methods of CompletableFuture in fact overrides original exception (though, this is undocumented).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant