I Use the AppDomain.UnhandledException Event to catch unhandled exceptions. I use a MessageBox.Show() instead of Console.WriteLine in the example;
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
try
{
throw new Exception("1");
}
catch (Exception e)
{
MessageBox.Show("Catch clause caught : " + e.Message);
}
throw new Exception("2");
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
MessageBox.Show("MyHandler caught : " + e.Message);
}
The example says the output should be:
// The example displays the following output:
// Catch clause caught : 1
//
// MyHandler caught : 2
Instead my ex.Message in the UnhandledExceptionEventHandler returns this:
MyHandler caught : 'The invocation of the constructor on type 'FlashMaps.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'.
When I expected it to return what the example displays:
MyHandler caught : 2
Thank you for your help.