Make node.js not exit on error

You can attach a listener to the uncaughtException event of the process object.

Code taken from the actual Node.js API reference (it’s the second item under “process”):

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.');

All you’ve got to do now is to log it or do something with it, in case you know under what circumstances the bug occurs, you should file a bug over at Socket.IO’s GitHub page:
https://github.com/LearnBoost/Socket.IO-node/issues

Leave a Comment