How to identify problem when program crashes without showing error?
Asked Answered
Y

6

10

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

Yellowish answered 28/4, 2009 at 14:24 Comment(0)
G
15
  1. You could add a try/catch/finally construct around your Main() entry method's body.

  2. For WinForms, you can add a ThreadException handler, just before Application.Run(), to catch exceptions thrown in WinForms UI event handlers:

    Application.ThreadException +=
       new ThreadExceptionEventHandler(Application_ThreadException);
    
  3. All other unhandled exceptions can be caught using:

    AppDomain.CurrentDomain.UnhandledException +=
       new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    

    But it's worth mentioning that this only allows you to log/report the exception - you cannot prevent the application from closing once you exit this final handler.

  4. Visual Studio can also be configured to break on first chance exceptions, and external debuggers (like WinDbg with managed SoS extensions) can catch first-chance exceptions too (http://www.codeproject.com/KB/debug/windbg_part1.aspx).

Also, use a logging framework like log4net to add useful logging to your app and dump exception information before the application closes.

Galvanoscope answered 28/4, 2009 at 14:48 Comment(0)
B
2

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.

Brookweed answered 28/4, 2009 at 14:35 Comment(0)
E
2

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.

Eldoraeldorado answered 28/4, 2009 at 14:39 Comment(1)
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.Spermatogonium
C
1

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.

Counterfoil answered 28/4, 2009 at 14:46 Comment(0)
W
0

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...

Wheelbase answered 28/4, 2009 at 14:46 Comment(0)
P
0

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.

Potheen answered 28/4, 2009 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.