Created
November 6, 2017 21:58
-
-
Save pellse/0a1e189a65acd2124cb3ff2c9e9f208e 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
public interface Customer { | |
... | |
List<Order> getOrders(); | |
} | |
try { | |
List<Customer> customers = queryDatabaseForCustomers(); // Expected to throw SQLException | |
handleAllOrdersOf(customers); // Not expected to throw SQLException | |
} catch (SQLException e) { | |
// Handle the exception from queryDatabaseForCustomers() | |
} | |
private void handleAllOrdersOf(List<Customer> customers) { // No throws clause here | |
Optional.ofNullable(customers) | |
.orElseGet(Collections::emptyList).stream() | |
.map(Customer::getOrders) // List of orders already populated | |
.forEach(this::processOrder); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment