Skip to content

Instantly share code, notes, and snippets.

@pellse
Created November 6, 2017 21:58
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 pellse/0a1e189a65acd2124cb3ff2c9e9f208e to your computer and use it in GitHub Desktop.
Save pellse/0a1e189a65acd2124cb3ff2c9e9f208e to your computer and use it in GitHub Desktop.
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