C# 反应界面';s ReactiveCommand异常处理

C# 反应界面';s ReactiveCommand异常处理,c#,.net,exception-handling,system.reactive,reactiveui,C#,.net,Exception Handling,System.reactive,Reactiveui,我试图处理在ReactiveUI(7.4.0.0)的命令中抛出的异常,但似乎所有内容都在内部的某个地方被允许,并且除了在VisualStudio的输出窗口中之外,再也不会出现。 我的测试代码如下: class Program { static void Main(string[] args) { try { var ata = ReactiveCommand.CreateFromTask(async () => awa

我试图处理在ReactiveUI(7.4.0.0)的命令中抛出的异常,但似乎所有内容都在内部的某个地方被允许,并且除了在VisualStudio的输出窗口中之外,再也不会出现。 我的测试代码如下:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            var ata = ReactiveCommand.CreateFromTask(async () => await AsyncTaskThrowException());
            ata.ThrownExceptions.Subscribe(ex => Console.WriteLine($"async with await:\t{ex.Message}"));
            ata.Execute();
            // Exception thrown: 'System.InvalidOperationException' in System.Reactive.Windows.Threading.dll
            // Exception thrown: 'System.Exception' in Test.exe
            // Exception thrown: 'System.Exception' in mscorlib.dll

            var atna = ReactiveCommand.CreateFromTask(() => AsyncTaskThrowException(),null, RxApp.MainThreadScheduler);
            atna.ThrownExceptions.Subscribe(ex => Console.WriteLine($"async without await:\t{ex.Message}"));
            atna.Execute();
            // Exception thrown: 'System.InvalidOperationException' in System.Reactive.Windows.Threading.dll
            // Exception thrown: 'System.Exception' in Test.exe

            var ta = ReactiveCommand.CreateFromTask(async () => await TaskThrowException());
            ta.ThrownExceptions.Subscribe(ex => Console.WriteLine($"async without await:\t{ex.Message}"));
            ta.Execute();
            // Exception thrown: 'System.InvalidOperationException' in System.Reactive.Windows.Threading.dll
            // Exception thrown: 'System.Exception' in Test.exe

            var tna = ReactiveCommand.CreateFromTask(() => TaskThrowException());
            tna.ThrownExceptions.Subscribe(ex => Console.WriteLine($"async without await:\t{ex.Message}"));
            tna.Execute();
            // Exception thrown: 'System.InvalidOperationException' in System.Reactive.Windows.Threading.dll
            // Exception thrown: 'System.Exception' in Test.exe
            // Exception thrown: 'System.InvalidOperationException' in System.Reactive.Windows.Threading.dll

            var sf = ReactiveCommand.Create(() => ThrowException());
            sf.ThrownExceptions.Subscribe(ex => Console.WriteLine($"sync:\t{ex.Message}"));
            sf.Execute();
            // Exception thrown: 'System.InvalidOperationException' in System.Reactive.Windows.Threading.dll
        }
        catch (Exception ex)
        {
            Debug.WriteLine($"{nameof(ex.Message)}: {ex.Message}");
            Debug.WriteLine($"{nameof(ex.StackTrace)}: {ex.StackTrace}");
        }

        Console.ReadLine();
    }

    static async Task<string> AsyncTaskThrowException()
    {
        await Task.Delay(100);
        throw new Exception("Exception in async Task");
    }

    static Task<string> TaskThrowException()
    {
        throw new Exception("Exception in non-async Task");
    }

    static string ThrowException()
    {
        throw new Exception("Exception in sync func");
    }
}
但还是会扔东西

您能帮助我理解为什么其他
异常
无法通过管道传输到
ThrownExceptions
,以及如何完全处理错误,使它们不会被记录到输出窗口中吗

谢谢

Execute()。为了让它正常工作,你应该订阅它。它的名字有点不好,但命名时找不到更好的名字。
ReactiveCommand.CreateFromTask(() => TaskThrowException());