Skip to content

Instantly share code, notes, and snippets.

@noahlz
Created March 6, 2013 00:06
Show Gist options
  • Save noahlz/5095589 to your computer and use it in GitHub Desktop.
Save noahlz/5095589 to your computer and use it in GitHub Desktop.
What did I do in a prior life to have to look at code like this?
public Result processCommand(Data data) {
try {
return doStuff();
// fuck it, just catch everything
} catch (Exception ex) {
String message = ex.getMessage() != null ? message : "LOL OOPS!";
return new Result(message);
}
}
// 1) Why catching all Exceptions?
// 2) The code was throwing java.lang.NullPointerException. getMessage() returns null!!!
// 3) How about some fucking logging instead of just returnning a useless error message?
@noahlz
Copy link
Author

noahlz commented Mar 6, 2013

BONUS:

Code that throws NPE in doStuff() is actually logging code like the following:

logger.info("param 1: %s param 2: %s param 3 %s", 
  paramA.toString(),
  paramB.toString(),
  paramC.toString());

Guess what happens if any of those params are null? :trollface:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment