Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
Created August 25, 2015 14:49
Show Gist options
  • Save RobertFischer/ca2bad03f5e28946ba66 to your computer and use it in GitHub Desktop.
Save RobertFischer/ca2bad03f5e28946ba66 to your computer and use it in GitHub Desktop.
Lambda for the pattern of eating exceptions
public class ExceptionEater {
private static final Logger log = //TODO Create Logger
public static <T> T swallowNPE(Supplier<T> producer) {
try {
return supplier.get();
} catch(NullPointerException npe) {
log.info("NullPointerException being swallowed", npe);
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment