Rxjs
流很简单,我遇到了这种情况:
Rx.Observable
.fromArray([1,2,3,4,5,6])
// if commented from here
.windowWithCount(2, 1)
.selectMany(function(x) {
return x.toArray();
})
// to here .. the error bubbles up
.subscribe(function(x) {
console.log('x:',x)
throw new Error("AAHAAHHAHA!");
});
带有windowWithCount + selectMany
错误的错误会在内部静默捕获,并且无法捕获,也不会在控制台中通知
评论这2个块,至少在控制台上通知了错误,
我不认为这应该是这样,还是我错过了什么?
这是jsbin
您的订阅函数永远不会抛出异常。RxJs建模异步信息流,其中观察者代码通常与生产者代码异步运行(例如,不在同一调用堆栈上)。您不能依靠错误传播回生产者。
Rx.Observable
.fromArray([1,2,3,4,5,6])
// if commented from here
.windowWithCount(2, 1)
.selectMany(function(x) {
return x.toArray();
})
// to here .. the error bubbles up
.subscribe(function(x) {
try {
console.log('x:',x)
throw new Error("AAHAAHHAHA!");
}
catch (e) { console.log('error: ' + e); }
});
话虽如此,RxJS似乎正在“吃掉”这个特殊异常,这可能是一个错误。RxJS尽其所能将未观察到的异常作为主机中未处理的异常引发。在这种情况下,这种机制似乎无法正常工作。您应该在GitHub上打开一个问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句