DEV Community

Discussion on: Anatomy of a JavaScript Error

Collapse
offirmo profile image
Offirmo

Wrong info in section "Manually throwing errors":

throw 'Invalid input'; <- This will automatically create an instance of an Error object with the message β€œInvalid input”, but the error instance can also be created manually and passed around.

No, no, no! That will throw a useless string, not an Error. The string will have no helpful stack trace and may trigger a cascade of failures in error handlers expecting an Error object.

ALWAYS throw an error, NEVER throw a string or anything else.

References: