views:

173

answers:

3

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.

A: 

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?

Rob van Groenewoud
-1. While, yes, he should be catching the exceptions he knows about, it's pretty standard practice to catch all unhandled exceptions for the purposes of logging or a custom error message, then exit as gracefully as possible.
Adam Robinson
@Adam: Ah, of course, I guess I misinterpreted the question. You're right about the graceful exit. Sorry 'bout that, it has been a long day ;-)
Rob van Groenewoud
The program is pretty complex and not initially developed by myself. I need to put something like that to see what is unhandled as quick solution. However, don't want an artifact similar to scary windows reporting message box. I just need my own nice looking, informative msg box.
Michael
A: 

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.

deltreme
...and they can also be caused by an unhandled exception.
Adam Robinson
No p/invokes nor unsafe{} blocks, I simplified up to the just simple application with nullreferenceexception in constructor. All unhandled exceptions are causing error report dialog at the end, even throwing exception myself then catching in mentioned block is causing same.Using vs2008
Michael
A: 

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