As titled.
I've been googling around and read threads...
I am very sure there is no where else do a e.Handle to stop the exception to bubble up to UnhandledException handler.
And I test my code as follows:
App.xaml.cs
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException +=
CurrentDomain_UnhandledException;
Application.Current.DispatcherUnhandledException +=
Current_DispatcherUnhandledException;
}
private void Current_DispatcherUnhandledException(
object sender,
DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.Exception.StackTrace);
e.Handled = true;
}
void CurrentDomain_UnhandledException(
object sender,
UnhandledExceptionEventArgs e)
{
MessageBox.Show(e.ExceptionObject);
}
}
A ViewModel property binding to DataGrid's SelectedItem:
private object _selectedItem;
public object SelectedItem
{
get
{
return this._selectedItem;
}
set
{
throw new Exception("Test");
if (this._selectedItem == value)
return;
this._selectedItem = value;
this.RaisePropertyChanged();
}
}
For some reason everywhere else I can see the exception being handled, message box showed up. But only when I do select in DataGrid, trigger the setter in SelectedItem, the exception only shown in Visual Studio, but not being handled by the handlers.... What is the reasons?