Last active
March 26, 2018 12:11
-
-
Save jasmine-k/8d2809d7cb767d47824c5e85835eea57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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