Exercise Solutions: Exceptions

Zero Division: Throw

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

Back to the exercises