1

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?

Community
  • 1
  • 1
King Chan
  • 4,212
  • 10
  • 46
  • 78
  • VS is configured to break on some exceptions. Also, I don't think it knows that you're catching the exception in a completely different place, so it treats it as an unhandled exception. –  Oct 07 '15 at 14:16

1 Answers1

0

Sometimes if your using TPL
i.e Tasks Actions, and Funcs if I call BeginInvoke AppDomain.CurrentDomain.UnhandledException does not catch their exceptions.

SHM
  • 7
  • 1