Darren Young
Darren Young

Reputation: 11100

Unhandled Exception

I have written a utility that monitors for Unhandled Exceptions and then creates a minidump in the event that one happens.

Is there a way, when the event triggers, rather than having the standard messagebox displaying the unhandled exception, could I disable that and display my own with different information?

Thanks.

Upvotes: 2

Views: 2717

Answers (4)

Mike Dour
Mike Dour

Reputation: 3766

Handle the Application.ThreadException event to show your own error messages.

You can hook the event at the top of your main method like this:

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

And then you need the Handler method:

static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
    MessageBox.Show(e.Exception.ToString());
}

Edit: You can also handle the AppDomain.UnhandledException event because certain exceptions don't go through the ThreadException handler.

Upvotes: 2

Cédric Guillemette
Cédric Guillemette

Reputation: 2408

Have a look at Application.SetUnhandledExceptionMode.

Upvotes: 0

You can do that ,

catch(Exception e)
{
throw new Exception("This is unhandled exception");
}

Upvotes: 1

Shamim Hafiz - MSFT
Shamim Hafiz - MSFT

Reputation: 22114

If you are implementing it, you can do whatever you want with it. Show it on MessageBox or write it to a log file.

Upvotes: 2

Related Questions