在达到应用程序级别之前捕获未处理的异常 [英] Catching an unhandled exception prior to it reaching Application level

查看:172
本文介绍了在达到应用程序级别之前捕获未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用调度程序捕获我们的WPF应用程序中的任何未处理的异常。这是在我们的app.xaml.cs文件中定义的,它工作得很好。然而,我们有一种情况,我们想检测并捕获在特定WPF用户控件中发生的任何未处理的异常。我们希望能够在应用程序级别的处理程序接收和处理之前拦截与该控件相关的任何未处理的错误。当我们尝试为User Control调度程序设置一个处理程序时,未处理的erro总是似乎在应用程序级别处理,然后在用户控制级别处理。尽管我们把Handled = True放在两个处理程序中。没有工作线程被使用。

We use the Dispatcher to catch any unhandled exceptions in our WPF app. This is defined in our app.xaml.cs file and it works very well. However we have a situation where we want to detect and trap any unhandled exceptions that happen in a specific WPF User Control. We would like to be able to intercept any unhandled erros related to that control prior to them being received and handled by the handler at the app level. When we try to set up a handler for the User Control dispatcher the unhandled erro always seems to get handled at the application level first and then at the user control level. Even though we put Handled=True in both of the handlers. No worker threads are being used.

我们知道我们可以进入用户控件和所有调用的代码,并设置try {} catch {}块并抛出自定义异常但是我们希望有更多的关键解决方案。

We know we can go into the user control and all the code it calls and setup try{}catch{} blocks and throw custom exceptions but we were hoping for a bit more of a turn key solution.

任何想法?

希望这个问题有意义。

推荐答案

没有像用户控制调度程序这样的事情。每个线程总是最多有一个主动调度程序。因此,处理Dispatcher.UnhandledException事件的处理程序的顺序仅由其注册顺序定义。

There's no such thing as a "User Control dispatcher". There's always at most one active dispatcher per thread. Thus, the order in which your handlers for Dispatcher.UnhandledException events will be processed is defined only by the order in which they are registered.

这篇关于在达到应用程序级别之前捕获未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆