vendredi 8 mai 2020

Appropriate way to throw an error in if-else block

I would like to know, which one (A or B) is the appropriate way of code writing for throw statement in if-else block:

The below block is for illustration purpose and assuming things are defined

//A

if(ruleId !=100)
      throw new RuleError(RULES_EXCEEDED);
const getRuleList = getRules(rule);
// Some more code down the line.....

//B

if(ruleId !=100)
      throw new RuleError(RULES_EXCEEDED);
else {
 const getRuleList = getRules(rule);
 // Some more code down the line.....
}

The only difference in B is an explicit use of else statement. My question is here, what is the best way to write. (This is an nodejs example but the theory will be applicable to other languages well)

Aucun commentaire:

Enregistrer un commentaire