Node.js: Break on Uncaught Exceptions

In the event the implemented error handling isn’t what it’s all cracked up to be, having the Node.js debugger break on uncaught exceptions is quite simple:

Assume the following code, where bogus  is undefined:

Line 3 will terminate the application (normally), and log an exception in stdout (or the console, a log, etc.) — even when Node.js is in debug mode.

To debug this uncaught exception JIT, the implementation may be as follows:

Run the above application (whose filename is “index.js”) as node --debug index.js  and after 2 seconds (notice the timeout) the exception will be uncaught, but the process will break on line 5 for debugging.

See this gist for an auxiliary and shortened reference.