Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jasmine-k
Last active March 26, 2018 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasmine-k/8d2809d7cb767d47824c5e85835eea57 to your computer and use it in GitHub Desktop.
Save jasmine-k/8d2809d7cb767d47824c5e85835eea57 to your computer and use it in GitHub Desktop.
private static void exception() {
Integer age = -1;
CompletableFuture<String> exceptionFuture = CompletableFuture.supplyAsync(() -> {
if (age < 0) {
throw new IllegalArgumentException("Age can not be negative");
}
if (age > 18) {
return "Adult";
} else {
return "Child";
}
}).exceptionally(ex -> {
System.out.println("Oops! We have an exception - " + ex.getMessage());
return "Unknown!";
});
exceptionFuture.thenAccept(System.out::println); //Unknown!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment