I am working on a Windows Forms App. I have attached a standard
UnhandledExceptionEventHandler to the current domain to catch
unexpected errors. In my application, when I trigger an unhandled
error, my handler does not get hit - I get the standard ugly run time
error. The strange thing is, I tried the exact same code in a new,
windows forms application, and when I trigger an unhandled exception,
the code works fine (the JIT compiler dialog box comes up, then my
exception handler runs).
The only thing different about the two applications is that the form
in the application that is not working is in a MDI child form. I have
pasted the same code, however, into the Main() of the parent form and
triggered an error there, with the same result, the code does not get
hit.
Are there some VID settings that I am missing that could be varying
between the applications to cause this behavior?
The code snippet that is misbehaving is as follows:
// in the form constructor
AppDomain adCurrent = AppDomain.CurrentDomain;
adCurrent.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledExceptionH andler);
// in the form constructor to trigger the error
decimal dec = Convert.ToDecimal("apple");
private static void UnhandledExceptionHandler(object sender,
UnhandledExceptionEventArgs ue)
{
Exception unhandledException = (Exception) ue.ExceptionObject;
if (!EventLog.SourceExists("Intake"))
{
EventLog.CreateEventSource("Intake","Intake Log");
}
EventLog eventLog = new EventLog();
eventLog.Source = "Intake";
eventLog.WriteEntry(unhandledException.Message);
MessageBox.Show("unhandled exception");
}