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

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

Description

@vsilaev

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions