Skip to content

Instantly share code, notes, and snippets.

@babjo
Created November 27, 2017 15:18
Show Gist options
  • Save babjo/6b37572661311bff03581b3f4b8a365d to your computer and use it in GitHub Desktop.
Save babjo/6b37572661311bff03581b3f4b8a365d to your computer and use it in GitHub Desktop.
String name = null;
// ...
CompletableFuture<String> completableFuture
= CompletableFuture.supplyAsync(() -> {
if (name == null) {
throw new RuntimeException("Computation error!");
}
return "Hello, " + name;
})}).handle((s, t) -> s != null ? s : "Hello, Stranger!");
assertEquals("Hello, Stranger!", completableFuture.get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment