Skip to content

Instantly share code, notes, and snippets.

@JulienSansot
Created April 7, 2015 05:59
Show Gist options
  • Save JulienSansot/875a22b4a2bd91151ea6 to your computer and use it in GitHub Desktop.
Save JulienSansot/875a22b4a2bd91151ea6 to your computer and use it in GitHub Desktop.
node error handling
var util = require('util');
var d = require('domain').create();
d.on('error', function(err){
try {
// make sure we close down within 10 seconds
var killtimer = setTimeout(function() {
process.exit(1);
}, 10000);
// But don't keep the process open just for that!
killtimer.unref();
console.log('critical error ' + util.inspect(err, { showHidden: true}));
} catch (er2) {
// oh well, not much we can do at this point.
console.error('Error ', er2);
}
});
d.run(function(){
/*
*
* DO YOUR STUFF HERE
*
*
*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment