Question

In my C# app, even I handle exception :

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException +=
    new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

and then in handler showing dialog box and doing Application.Exit still getting windows error reporting dialog with Send, Don't Send...

How to prevent windows error reporting dialog from popping up?


In fact if the exception is thrown from main form constructor then the program ends up with Windows error report dlg. Otherwise if from some other location of UI thread, then as expected.

Was it helpful?

Solution

You'll need to terminate the app yourself. This will do it:

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
  var ex = e.ExceptionObject as Exception;
  MessageBox.Show(ex.ToString());
  if (!System.Diagnostics.Debugger.IsAttached)
    Environment.Exit(System.Runtime.InteropServices.Marshal.GetHRForException(ex));
}

OTHER TIPS

The dialog that presents the choice to send or not send an error report to Microsoft is beyond exceptions. This might happen if you use unsafe{} blocks or you use p/invoke's which perform some illegal operation.

I think you should not be fighting the symptoms of your problem. The unhandled exceptions should not happen in the first place.

Do you have any clues on what is causing them?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top