WPF MVVM Light Exception not getting caught by Application_DispatcherUnhandledException
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. I开发者_Go百科t 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
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.
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/
精彩评论