Check out "Do you speak JavaScript?" - my latest video course on advanced JavaScript.
Language APIs, Popular Concepts, Design Patterns, Advanced Techniques In the Browser

Catch uncaught Exception in Node.JS

I'm working on a very simple tool which compiles some stuff. The big problem is that if I write something wrong I can't catch the exception from the compiler and the nodejs's process exists. Then I have to go back to the console and run the app again. That's of course not acceptable. Thankfully there is a workaround.

process.on('uncaughtException', function(err) { console.log('Caught exception: ' + err); });

setTimeout(function() { console.log('This will still run.'); }, 500);

// Intentionally cause an exception, but don't catch it. nonexistentFunc(); console.log('This will not run.');

If you enjoy this post, share it on Twitter, Facebook or LinkedIn.