Properly handling exceptions thrown in a thread or via the WPF dispatcher

江枫思渺然 提交于 2020-01-25 07:30:27

问题


When a thread throws an exception that is unhandled, it terminates. What is the proper way to handle exceptions thrown on threads and how to propogate relevant exception data to other parts of the code that would need to subscribe to notifications? Is there an INotifyThreadPoorlyDesigned interface that I missed somewhere?

Same applies for how to handle stuff dispatched to the WPF UI.


回答1:


To handle work that throws an exception on a dispatcher thread, simply hook the Application::DispatcherUnhandledException event. To handle non-dispathcer thread exceptions, you just need to hook the standard AppDomain::UnhandledException event.



来源:https://stackoverflow.com/questions/1703056/properly-handling-exceptions-thrown-in-a-thread-or-via-the-wpf-dispatcher

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