Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify problem when program crashes without showing error?

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

like image 566
Josh Avatar asked Apr 28 '09 14:04

Josh


2 Answers

  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.

like image 169
Groo Avatar answered Sep 27 '22 18:09

Groo


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.

like image 30
Tony Avatar answered Sep 27 '22 18:09

Tony