After a long battle, finally, I found a very simple way to implement exception handling inside the ViewModel. When creating a BindingListener that inherits from DefaultTraceListener, there is certainly a great way to find your binding errors during debug mode, it will not catch exceptions that occurred inside the ViewModel when the running solution is standard. But AppDomain.CurrentDomain.FirstChanceException will be.
App.xaml.cs:
AppDomain.CurrentDomain.FirstChanceException += new EventHandler<System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs>(CurrentDomain_FirstChanceException);
private void CurrentDomain_FirstChanceException(object sender, FirstChanceExceptionEventArgs e)
{
Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("Error Occurred \n\r" + e.Exception.Message + "\n\r" + e.Exception.StackTrace, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error)));
}
lucas source
share