ruk·si

🟢 Node
Domains

Updated at 2013-07-04 09:04

Domains allow catching JavaScript errors in more controlled manner, rather than relying on try-catches in process level. Remember to clean up resources after catching errors though.

var myDomain = require('domain').create();
myDomain.on('error', function(err) {
    console.log('Ignored: ' + err);
});
myDomain.run(function() {
    setTimeout(function() {
        throw new Error('Listen to me!')
    }, 50);
});
Ignored: Error: Listen to me!

Sources

  • Async JS