jhunter
jhunter

Reputation: 1892

Winforms unceremoniously quits with "unhandled exception"

The program spits up one of those boxes saying an unhandled exception has occurred and the application must quit. The only clue I get to solve the problem is this in the event log:

Event Type: Error Event Source: .NET Runtime 2.0 Error Reporting Event Category: None Event ID: 5000 Date: 1/9/2009 Time: 8:47:44 AM User: N/A Computer: DADIEHL Description: EventType clr20r3, P1 crm.client.exe, P2 1.0.1.0, P3 49667f61, P4 mscorlib, P5 2.0.0.0, P6 471ebc5b, P7 c35, P8 59, P9 system.formatexception, P10 NIL.

So I added the following code to program.cs:

try
{
    Application.Run(new WindowContainer());
}
catch (Exception exc)
{
    new DialogException(exc).ShowDialog();
}

Just so I could catch any exception, but the users are still getting the same message that says the app has to quit. I cannot reproduce this on my computer and thus can't use the debugger to narrow it down. Does anyone know of a way to collect more information or have any ideas what the issue is?

Upvotes: 3

Views: 1587

Answers (2)

Lurker Indeed
Lurker Indeed

Reputation: 1531

If you don't want to make code changes right this second, I'd probably use WinDbg with the SOS extension, so you can at least get a stack trace - very handy for these types of crashes.

Real World Walkthrough w/WinDbg

You could try handling the UnhandledExceptionEvent. From MSDN:

UnhandledExceptionEvent

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1503140

It may well be that the exception is being thrown on a different thread.

Two events you may want to add handlers to:

Add handlers which log the exception and you'll have a lot more information.

The behaviour of unhandled exceptions in non-UI threads changed from .NET 1.1 to 2.0. They used to just be swallowed but now they halt the app. There's an app.config flag you can use to choose the old behaviour if you want - but it's not really recommended, as an exception in another thread may well mean that your app is now unstable. I can't remember the details of the setting at the minute, but I can look them up if you want.

Upvotes: 15

Related Questions