Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to collect crash data?

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

I'm working in MS Visual Studio C#.

From an implementation point of view, does it make sense to put a try/catch loop in my main program.cs file, around where the application is run? Like this:

        try
        {
            Application.Run(new myMainForm());
        }
        catch (Exception ex)
        {
            //the code to build the report I want to send and to 
            //pop up the Problem Report form and ask the user to send

        }

or does it make sense to put try/catch loops throughout pieces of the code to catch more specific exception types? (I'm thinking not because this is a new application, and putting in more specific exception catches means I have an idea of what's going to go wrong... I don't, which is why the above seems to make sense to me.)

-Adeena

like image 729
adeena Avatar asked Dec 14 '08 16:12

adeena


People also ask

What is a crash database?

Crash-level data contains information about the entire crash, such as crash location, crash date, total fatalities in the crash, and whether alcohol was involved in the crash.

What kind of quantitative data is collected and analyzed during crash testing?

The most common types of quantitative data used for safety analysis are crash data, traffic volumes, and roadway characteristics. Qualitative or anecdotal information from stakeholders also is commonly used in safety analysis.

Where is crash data stored?

The SRS airbag control module is the unit in all vehicles that registers when an accident occurs, and stores information in the form of hard codes and crash data. This crash data can be accessed through an OBD airbag scanner.


2 Answers

I think you are right, you would not know what's going to go wrong, which is the point.

However, you might as well consider adding a handler to the ThreadException event instead.

The code above will work but there will be scenarios where multi threading might be an issue with such code, since not all code inside your windows forms program will be running in the main Application.Run loop thread.

Here's a sample code from the linked article:

[STAThread]
static void Main() 
{
   System.Windows.Forms.Application.ThreadException += new ThreadExceptionEventHandler(ReportError);
   System.Windows.Forms.Application.Run(new MainForm());
}

private static void ReportError(object sender, ThreadExceptionEventArgs e)
{
   using (ReportErrorDialog errorDlg = new ReportErrorDialog(e.Exception))
   {
    errorDlg.ShowDialog();
   }
}

More documentation on MSDN.

On a minor point, using the ThreadException event also allow your main message loop to continue running in case the exception isn't fatal (i.e. fault-tolerance scenarios) whilst the try/catch approach may requires that you restart the main message loop which could cause side effects.

like image 95
chakrit Avatar answered Oct 03 '22 19:10

chakrit


From an implementation point of view, does it make sense to put a try/catch loop in my main program.cs file, around where the application is run?

Sure and always.

You should use Try/Catch-Blocks wherever you do something critical, that might raise an exception.

Therefore you can not really stick to a pattern for that, because you should now, when what exception will be raised. Otherwise these are unhandled exceptions, which let your program crash.

But there are many exceptions, that need not to stop the application entirely, exceptions, that just can be swallowed over, as they are expected and do not critically need the application to stop. Example for that are UnauthorizedAccessExceptions when moving or accessing data with your programm.

You should try to keep you Try/Catch-Blocks as small as needed, as well as to use not too much of them, because of performance.

Some out there use Try/Catch for steering the program's execution. That should entirely be avoided wherever possible, cause raising an Exception is performance killer number 1.

like image 33
Oliver Friedrich Avatar answered Oct 03 '22 17:10

Oliver Friedrich