Pablo
Pablo

Reputation: 29529

Getting Windows error reporting dialog

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.

Upvotes: 1

Views: 2136

Answers (3)

Hans Passant
Hans Passant

Reputation: 942508

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));
}

Upvotes: 3

C.Evenhuis
C.Evenhuis

Reputation: 26456

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.

Upvotes: 1

Rob van Groenewoud
Rob van Groenewoud

Reputation: 1884

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?

Upvotes: 0

Related Questions