2013-02-07 52 views
1

爲什麼domain不處理以下錯誤?爲什麼域名無法捕捉到異常?

var globalDomain = domain.createDomain(); 

globalDomain.run(function() { 
    // Why below exception does not get handled by globalDomain? 
    throw "some error"; 
}); 

globalDomain.on('error', function(msg) { 
    console.log("In global error event:" + msg); 
}); 

再次,它工作得很好用下面的代碼,

var globalDomain = domain.createDomain(); 

globalDomain.run(function() { 
    setTimeout(function(){ 
     throw "some error from timeout"; 
    },0); 
}); 

globalDomain.on('error', function(msg) { 
    console.log("In global error event:" + msg); 
}); 

回答

3
var globalDomain = domain.createDomain(); 

globalDomain.on('error', function(msg) { 
    console.log("In global error event:" + msg); 
}); 

globalDomain.run(function() { 
    // exception gets handled by globalDomain !! 
    throw "some error"; 
});