What is the best way to collect crash data?

后端 未结 6 666
悲哀的现实
悲哀的现实 2020-12-17 02:04

So I am sold on the concept of attempting to collect data automatically from a program - i.e., popping up a dialog box that asks the user to send the report when something g

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 02:47

    Wrapping a try catch around the whole application will mean the application will exit upon error.

    While using a try and catch around each method is hard to maintain.

    Best practice is to use specific try catches around units of code that will throw specific exception types such as FormatException and leave the general exception handling to the application level event handlers.

    try
            {
                //Code that could error here
            }
            catch (FormatException ex)
            {
                //Code to tell user of their error
                //all other errors will be handled 
                //by the global error handler
            }
    

    Experience will tell you the type of things that could go wrong. Over time you will notice your app often throwing say IO exceptions around file access so you may then later catch these and give the user more information.

    The global handlers for errors will catch everything else. You use these by hooking up event handlers to the two events System.Windows.Forms.Application.ThreadException (see MSDN) and AppDomain.UnhandledException (see MSDN)

    Be aware that Out of Memory exceptions and StackOverflowException may not be caught by any error catching.

提交回复
热议问题