With synchronous errors, you can nest error scopes like this:
try {
try {
throw Error('e')
} catch(e) {
if(e.message !== 'f')
throw e
}
} catch(e) {
handleError(e)
}
This is how I would expect it to work, but it doesn't (seems an error inside a domain error handler is thrown up to the top, skipping any domains in between):
var domain = require('domain');
var dA = domain.create();
dA.on('error', function(err) {
console.log("dA: "+ err); // never happens
});
dA.run(function() {
var dB = domain.create();
dB.on('error', function(err) {
throw err
});
dB.run(function() {
setTimeout(function() {
console.log('dB')
throw 'moo'
},0)
});
});
Is there a way to do this right?