gpt4 book ai didi

node.js - 为什么域没有捕获以下异常?

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:26 25 4
gpt4 key购买 nike

为什么域不处理以下错误?

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);
});

最佳答案

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";
});

关于node.js - 为什么域没有捕获以下异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14746645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com