0
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show($"e.Exception?.Message}\n*********\n*e.Exception?.Data.ToString()}**********{e.Exception.StackTrace}");
         e.Handled = true;
}

I use the above code in App.xaml.cs to catch any error unhandled in my code. If the Message would be : An item with the same key has already been added. because I tried to insert an existing key in a dictionary, how would I know which dictionary it was? Is that somewhere in e ? thanks Frank

Knarf
  • 51
  • 4
  • Possible duplicate of [Getting the variable name for NullReferenceException](https://stackoverflow.com/questions/34442419/getting-the-variable-name-for-nullreferenceexception) – Miamy Nov 13 '18 at 21:20

1 Answers1

0

The short answer: you would not.

CLR does not store the names of variables elsewhere. The explanation is given here: Getting the variable name for NullReferenceException.

But you can inspect e.data object, which has Keys and Values properties, so you can guess which instance cas has this values.

Also, you can get information about source code line where exception was thrown: How to get the name of the method that caused the exception

Miamy
  • 2,162
  • 3
  • 15
  • 32