Throwing Your Own Errors

When a function gets a value it can't use, throw new Error with a message that says what was wrong, make your own error class with extends Error for the problems your program knows about, and return a value instead when there's no mistake to report.

Updated

Cheat sheet: Throwing Your Own Errors
Category
JavaScript
Level
Journeyman
Tags
Custom Error, Error, extends, instanceof (javascript), JavaScript, software-development, throw (javascript)