views:

541

answers:

7

Hello,

Please let me know what steps I need to follow when my application crashes and closes showing the dialog containing "Don't send" and "Send error report" buttons.

What can I possibly do other than looking at the event viewer to solve this?

Thanks

+1  A: 

Ask your users if they can reproduce the error and how. If you can reproduce the error, run in debug in Visual Studio and follow the steps to cause the crash. Visual studio will enter debug mode where it catches the error. Form there you will be able to follow the stack trace and see what code is causing the error. Visual studio makes debugging pretty easy most of the time.

Tony
+1  A: 

Ideally you should use a logging library such as nLog or log4net to log any unhandled exceptions, and exceptions in general, by logging them in your code when they occur.

It can also help to have different levels of logging in your application to help you track down a problem when it's not running on your development machine. With nLog you can leave the logging in your production code and enable / disable log output through the use of a logging config file.

I've not used log4net so I don't know if it has a similar feature.

RSlaughter
Log4Net offers the same - usually the logging granularity is at least class level and then you can decide to use debug log only for this class. The log level can also be changed while the app is running.
weismat
+1  A: 

The "send/don't send" errors tend to happen when you have an unhandled exception in a background thread (the main thread will show that continue/quit .NET dialog with a stack trace).

Add an exception handler to your thread's function and log from there:

void RunMyThread()
{
    try
    {
        // background thread code
    }
    catch (Exception ex)
    {
        // Log the exception
    }
}

This is highly simplified, and may not be how you want to handle an exception. But hopefully this will get you moving in the right direction.

Jon B
A: 

Use WinDBG to debug the issue. You can make it break (as in stop on a breakpoint) when an exception is thrown, and then examine the stacktrace... objects in scope etc...

Krzysztof Koźmic
+2  A: 
  1. You could add a try/catch/finally construct around your Main() entry method's body.

  2. Add a ThreadException handler, just before Application.Run(), to catch thread exceptions also:

    Application.ThreadException +=
       new ThreadExceptionEventHandler(Application_ThreadException);
    
  3. Using an external debugger (like WinDbg with managed SoS extensions), you can even catch first-chance exceptions in your code (http://www.codeproject.com/KB/debug/windbg_part1.aspx).

Groo
A: 

If it happens at a customer site, and isn't easily reproducable inside a developers debugger, you could do some post mortem debugging. I like to use Userdump to gather a memory dump file (.DMP). Then I use windbg for analysis.

pj4533