mercredi 23 novembre 2016

try/catch vs if/else throwing NullPointerException

What do i choose when wanting to throw an NullPointerException?

1)

if(parameter != null){
  // do something
} else {
  Log.error("Reason for Exception.");
  throw new NullPointerException();
}

2)

try{
  // do something
} catch (NullPointerException npe) {
  Log.error("Reson for Exception.");
  throw npe;
}

Aucun commentaire:

Enregistrer un commentaire