.NET Reactive框架:ReplaySubject OnError:为什么会抛出异常?
注意:我指的是 .NET 4 版本的 RX。
我一直在使用 RX 的 ReplaySubject 类。我正在调用 OnError,并以异常作为参数。
我原以为它会通知所有 OnError 订阅者并向他们传递异常,但它只是抛出异常,之后异常就不再被处理。
代码很简单,你可以看一下GitHub上的代码。 https://github.com/arielbh/CodeCommander/blob/master /CodeValue.CodeCommander/CommandBase.cs 第 117 行是 OnNext 调用。
有什么想法吗?显然我想要我期望发生的行为。 谢谢阿里尔
Note: I'm referring to the .NET 4 version of RX.
I've been using the ReplaySubject class of RX. I'm calling the OnError with an exception as the parameter.
I was expecting that it will notify all the OnError subscribers and will pass them the exception, instead it just throws the exception and after that the exception just go unhandled.
Code is very simple, you can have a look at the code on GitHub.
https://github.com/arielbh/CodeCommander/blob/master/CodeValue.CodeCommander/CommandBase.cs
Line 117 is the OnNext call.
Got any ideas? obviously I want the behavior I'm expecting to happen.
Thanks
Ariel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我找到了原因。
如果您没有订阅 OnError,则默认行为是抛出异常。
我不够小心,所以没有观察到引发错误的主题。
更多信息:
http://social.msdn.microsoft.com/Forums/en/rx/thread/3125094b-1ab2-4d01-8f44-fb68ef913f43
OK, I found out the cause of it.
If you are not subscribed to OnError, than the default behavior is throwing the exception.
I was not careful enough so the Subject that raises the error was no being observed.
More info:
http://social.msdn.microsoft.com/Forums/en/rx/thread/3125094b-1ab2-4d01-8f44-fb68ef913f43
我也遇到了这种奇怪的行为。我创建了自己的扩展方法来获得我期望的行为。
I hit this strange behavior too. I created my own extension method to get the behavior I was expecting.