Created
April 7, 2015 05:59
-
-
Save JulienSansot/875a22b4a2bd91151ea6 to your computer and use it in GitHub Desktop.
node error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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