Monday, September 4, 2017

JavaScript Exceptions vs. Errors

A JavaScript exception is a value that is thrown as a result of an invalid operation or as the target of a throw statement. While it is not required that these values are instances of Error or classes which inherit from Error, all exceptions thrown by Node.js or the JavaScript runtime will be instances of Error.

Some exceptions are unrecoverable at the JavaScript layer. Such exceptions will always cause the Node.js process to crash.

This is why you can write:
throw new Exception("foo bar");
throw "foo bar";

No comments: