Exercise Solutions: Exceptions

Zero Division: Throw

1
2
3
4
5
6
function divide(numerator, denominator) {
   if (denominator === 0) {
      throw Error('You cannot divide by zero!');
   }
   return numerator/denominator;
}

Back to the exercises