tags:

views:

322

answers:

1

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  A: 

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.

Pavel Minaev