Thursday Night

Paul Betts’s personal website / blog / what-have-you

You can get the crash reports from Windows Error Reporting (Watson)

One of the things I see pop up on Stack Overflow all the time is, people wanting to hide or suppress the Windows Error Reporting dialog – the feature of Windows where crash reports are sent to Microsoft when your app crashes. Developers say, “MS doesn’t care about my app, what’s the point?” If they’re not so bright, they’ll write a try/catch block around their main() and hide all errors, then they’ll never find out why their apps crash in the field. Smarter developers will essentially write their own hacked-up version of WER with varying degrees of success. However, there’s a 3rd option that is superior:

Register with Microsoft, and get the WER Reports

Microsoft doesn’t just trash your reports, we will automatically aggregate them into distinct crashes (called ‘buckets’) and show you a ‘popularity contest’ of crashes – you can find out a ton of detailed information about what is happening in the field. Here’s the MSDN article detailing how to sign up. It takes a bit of leg work, but if you’re writing any sort of production-quality application, it’s 100% worth it.

But here’s what to do if you don’t believe me

Alright, so you have some super-good reason as to why you really don’t want this dialog to show up. Here’s what works on Win2k and higher (Vista has an API to do this explicitly though):

LONG KillSelfOnUnhandledException(LPEXCEPTION_POINTERS WhyGodWhy)
{
    TerminateProcess(GetCurrentProcess(),
            WhyGodWhy->ExceptionRecord->ExceptionCode);

    // Never gonna get here
    return EXCEPTION_EXECUTE_HANDLER;
}

int main(int, char**)
{
    SetUnhandledExceptionFilter(KillSelfOnUnhandledException)
}

Written by Paul Betts

January 11th, 2010 at 11:43 am