Reputation: 31
Am using MVVM light toolkit for a WPF application. Somehow the Application_DispatcherUnhandledException method is not getting called for any exception thrown in the View/ViewModel. It gets called only if exception is thrown during load of the first Window(loaded by the app.xaml as the startup window) itself....then it simply doesn't get hit.. Anyone else facing this issue?
Thanks Anshulee
Upvotes: 0
Views: 986
Reputation: 3565
In MVVM Light the exception from view models are not thrown in UI thread. Below code raise exception in UI thread
App.Current.RootVisual.Dispatcher.BeginInvoke(() =>
{
throw new MyException("Exception occured.");
});
Credit goes to this article http://codifying.wordpress.com/2010/12/20/silverlight-unhandled-exception-and-mvvm-light/
Upvotes: 0
Reputation: 2200
Sounds like the exception might not be occurring on the UI thread. I'm not sure what the framework is doing under the hood. Anyways, check this out: http://www.codeproject.com/Articles/90866/Unhandled-Exception-Handler-For-WPF-Applications.aspx Non-UI threads are going to throw exceptions that your method by itself won't catch - you'll probably want to hook the AppDomain as well.
Upvotes: 2