Catching an unhandled exception prior to it reaching Application level

不问归期 提交于 2019-12-24 09:23:42

问题


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.

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.

Any Ideas?

Hope this question makes sense..


回答1:


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.



来源:https://stackoverflow.com/questions/1106107/catching-an-unhandled-exception-prior-to-it-reaching-application-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!