javascript - how to prevent node.js application from terminated for unhandled exception in setInterval? -



javascript - how to prevent node.js application from terminated for unhandled exception in setInterval? -

node.js application terminated unhanded exception in setinterval. seek prepare process.on('uncaughtexception', ..) , domain approaches (see below codes). application still terminated although exception handled.

function f () { throw error('have error') } process.on('uncaughtexception', function(err){ console.log("process.on uncaughtexception") }) var d = require('domain').create(); d.on('error',function(err){ console.log("domain.on error") }) d.run(function(){ setinterval(f, 1000) }) // programme terminated , output is: domain.on error

program terminated because there nil else process after setinterval(). in nodejs doc example, creates the server , bind port it. that's keeps application running. here illustration doc:

var d = require('domain').create(); d.on('error', function(er) { // error won't crash process, worse! // though we've prevented abrupt process restarting, leaking // resources crazy if ever happens. // no improve process.on('uncaughtexception')! console.log('error, oh well', er.message); }); d.run(function() { require('http').createserver(function(req, res) { setinterval(f, 1000); }).listen(8888); });

then if point browser localhost:8888, app not terminated

javascript node.js

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -