[英]exception swallowed in RaiseAndSetIfChanged
通常在反應式擴展中,任何未處理的異常都會冒泡並且通常會導致程序終止,並且除非訂閱ThrownExceptions,否則ReactiveUI會通過重新拋出異常來執行此操作。 因此,我驚訝地發現以下代碼示例(在RoslynPad中有效)實際上並未終止:
#r "nuget:ReactiveUI/9.13.1"
using System.Reactive.Linq;
using ReactiveUI;
class ReactiveExample : ReactiveObject
{
public ReactiveExample()
{
var o = this.ObservableForProperty(x => x.S, skipInitial: true).Select(x => x.Value);
o.Subscribe(s =>
{
Console.WriteLine("received value " + s);
throw new Exception("throw on value " + s);
});
//this.ThrownExceptions.Subscribe(e => throw new Exception("uncaught", e));
}
public string S
{
get => _s;
set => this.RaiseAndSetIfChanged(ref _s, value);
}
private string _s = "";
}
var r = new ReactiveExample();
r.S = "bar";
如果您通過在上面的相應行中進行注釋來訂閱ThrownExceptions,則很明顯確實會拋出異常。
這是一個錯誤還是一個功能? 我認為這是由ReactiveUI.IReactiveObjectExtensions.NotifyObservable中的try / catch引起的,如果ThrownExceptions observable沒有訂閱者而不是僅記錄它,我本來期望重新拋出異常(請參閱https:// github來自第382行的.com / reactiveui / ReactiveUI / blob / a4ee168dade8b5e3f34337fabd56eca10eca5200 / src / ReactiveUI / ReactiveObject / IReactiveObjectExtensions.cs )。
https://reactiveui.net/docs/handbook/default-exception-handler/
我建議你提交一個bug,因為異常應該傳播
值得注意的是ObservableForProperty主要用於內部使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.