custom-error
Create custom errors that inherit Error.
why
Extending Error is a real pain, so this library deals with the quirks, providing a clean API to extend Error that works across JS environments, including Node and browsers.
usage
Calling customError(errorTitle[, ParentError])
creates a new error class that can be called the
same way that Error
is called. The new error constructor will inherit from Error
, or from
ParentError
if you provide it.
examples
var customError = ;var ApocalypseError = ;instanceof Error // trueinstanceof ApocalypseError // truevar UnixApocalypseError =instanceof Error // trueinstanceof ApocalypseError // trueinstanceof UnixApocalypseError // trueif === 2038throw
Using prototype
UnixApocalypseErrorprototypeyear = 2038trythrowcatch errconsole // 2038
installation
npm install custom-error
license
MIT