- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个基本的 ReactiveCommand
。没有异步魔法,只有普通的 ReactiveCommand.Create()
。我 Subscribe()
的重载采用异常处理程序,但从未在所述异常处理程序中遇到断点(我没想到会这样)。我订阅了 ThrownErrors
,也从未在该异常处理程序中遇到断点(我有点预料到这一点)。
示例代码如下:
var myCommand = ReactiveCommand.Create();
// this does not seem to work
myCommand.Subscribe(
_ => { throw new Exception("oops"); },
ex => {
Console.WriteLine(ex.Mesage);
Debugger.Break();
});
//this does not seem to work either
myCommand.ThrownExceptions.Subscribe(
ex => {
Console.WriteLine(ex.Mesage);
Debugger.Break();
});
我做了功课,检查了题目中的问题和答案。
How to catch exception from ReactiveCommand?
我也检查了邮件列表,发现了这个: https://groups.google.com/forum/#!topic/reactivexaml/Dkc-cSesKPY
所以我决定将其更改为某种异步解决方案:
var myCommand = ReactiveCommand.CreateAsyncObservable(_ => this.Throw());
myCommand.Subscribe(
_ => { Console.WriteLine("How did we get here?"); },
// this is not expected to work
ex => {
Console.WriteLine(ex.Message);
Debugger.Break();
});
// however, I sort of expect this to work
myCommand.ThrownExceptions.Subscribe(
ex => {
Console.WriteLine(ex.Message);
Debugger.Break();
});
[...]
private IObservable<object> Throw()
{
Debugger.Break();
throw new Exception("oops");
}
然而,除了 Throw()
方法中的断点外,我从未遇到过任何断点。 :(
我做错了什么?我应该如何捕获此处的异常?
编辑:
但是,当我从可观察对象中抛出异常时,我确实遇到了异常处理程序断点,就像这样
private IObservable<object> Throw()
{
Debugger.Break();
return Task.Factory.StartNew(() =>
{
throw new Exception("oops");
return new object();
}).ToObservable();
}
问题修改为:“我是否能够处理方法内部的异常而不是可观察的异常?”
最佳答案
这是 ReactiveUI 当前版本中的一个错误 - 创建“执行”可观察对象时抛出的异常被吞噬,ReactiveCommand
的内部状态处于损坏状态。这已在下一版本中修复。
参见 this github issue了解详情。
关于c# - 如何捕获 ReactiveCommand 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36182904/
我已经看到一些关于使用 Observables 而不是带有 async/await 的任务的讨论。我目前几乎只使用 CreateFromTask。我一直在试图理解使用 CreateFromObserv
我有一个使用 ReactiveCommand 的 View 模型: public ReactiveCommand Command { get; } public MyViewModel() {
我正在努力处理一个 ReactiveUI 用例,我觉得它非常简单,必须有“开箱即用”的支持。但是我找不到它。 该场景是具有以下功能的基本搜索界面: 用户在其中输入搜索文本的搜索字符串文本框 显示结果的
我想用command实现textbox的KeyDown事件, 我想让命令可以识别KeyDown事件中的KeyEventArgs之类的键输入并做一些其他事情, 所以我想将命令参数传递给 Reactive
我正在使用 System.Windows.Interactivity 绑定(bind)一个 LoadedCommand,如下所示: 在我的 View 模型中,
我对 ReactiveCommand 处理 ObserveOn 和 SubscribeOn 的方式有疑问。 我有一个返回可观察的字符串序列的 API,它看起来像这样: public IObserva
当执行绑定(bind)到控件的 ReactiveCommand 时,我想将一个参数从我的 View 传递给我的 ViewModel。参数的类型应为 IJcUser 所以我这样定义命令: public
我想在命令执行之前设置忙标志和状态栏文本,并在它完成之后——重置标志和文本。我的工作代码在这里: Cmd = ReactiveCommand.Create(); Cmd.Subscribe(async
我知道如何处理 ReactiveCommand 调用的异步任务抛出的异常但是如何处理任务返回前抛出的异常? 在下面的例子中ThrowAndHandle命令将在执行时从异步任务中抛出异常,并将处理该异常
我有一个基本的 ReactiveCommand。没有异步魔法,只有普通的 ReactiveCommand.Create()。我 Subscribe() 的重载采用异常处理程序,但从未在所述异常处理程序
我订阅了一个命令的 IsExecuting: LoginCommand.IsExecuting.Subscribe(x => Log("Logging in")); 当我的 Command 被 Inv
我有这个 ReactiveCommand; LoadFileCommand = ReactiveCommand.CreateAsyncTask((_, cancellationToken) => Lo
我从一个冷的可观察对象创建了一个 react 命令。调用命令时,它会将 IsExecuting 更改为 true,并将 first emitted value 从 observable 更改回 fal
考虑在 ReactiveUI 中使用继承。我有带有 DoSomethingCommand 的 ViewModel 基类。此命令的“CanExecute”取决于属性 Prop1 public class
我刚刚开始使用 ReactiveUI。我有以下类(class): public class MainViewModel : ReactiveObject, IRoutableViewModel {
我熟悉 MVVM 的概念并使用过 MvvmCross,但我正在尝试 ReactiveUI 并尝试围绕一些概念进行思考。 我正在 WPF 中编写一个工具(可能分支到其他框架)供设计人员创建和编辑数据文件
我的 xaml ( 在此示例中仅显示 2 ) 中有几个 Tiles (TileLayoutControl Class),其可见性绑定(bind)到 bool 属性并通过 BooleanToVisibi
我想知道绑定(bind)到 ReactiveCommand 的 IsExecuting 的推荐方式. 问题是初始命令执行(在构造函数末尾开始)没有使用 IsLoading 更新 WPF 控件。作为绑定
我正在使用 ReactiveUI与 AvaloniaUI并且有一个带有多个 ReactiveCommands 的 ViewModel即扫描、加载和运行。 当 Observable 时调用扫描已更新(当
我缺乏经验,尤其是在 MVVM 方面,但尝试使用 ReactiveUI,并且我不理解我发现的演示 ReactiveCommand 的示例。我以前使用过 ICommand/DelegateCommand
我是一名优秀的程序员,十分优秀!