【发布时间】:2017-11-05 08:32:52
【问题描述】:
我已经在我的引导程序中覆盖了 OnUnhandledException,但在以下情况下它不会被调用:
public class Foo : IHandle<Bar> {
public void Handle(Bar message) {
// Do something that requires UI thread
}
public void DoSomething() {
eventAggregator.PublishOnBackgroundThread(new Bar());
}
}
调用handle方法时会抛出InvalidOperationException: The calling thread must be STA, because many UI components require this.,因为它是在后台线程而不是UI线程上执行的:
OnUnhandledException 在我的引导程序中从未捕获到该异常。 Application.DispatcherUnhandledException 事件处理程序也不会捕获它。
如何创建一个通用的异常处理程序来捕获这些类型的异常,而不必在任何地方实现 try/catch?
【问题讨论】:
标签: c# exception-handling caliburn.micro