Errors, Errors, Everywhere

ShinyYellow_error Error handling. You know you have to do…well, you should do it…well, maybe you will get the code working and then come back later and add proper error handling.

Let’s be honest, you will never go back and do it. If you can’t take time to do it right the first time, how do you expect to find time to do it over again?

Error handling is not the most fun aspect of programming, but doing it right can separate a buggy program from good solid code.

Seneca5 Error Logging Class

We have created a simple class that helps handle errors. It takes care of the most common needs for dealing with errors: Reporting, Cleaning, Displaying, and Logging. This is not an error handler, in the sense that it takes no particular action based on an error; you can still do that with code specific to the event. The purpose is to provide a way to make sure all errors are caught and recorded.

Features

  • Central collection of errors that occur throughout your program
  • Timestamps errors
  • Save errors to a file
  • Optionally supresses duplicate consecutive errors

Class Methods

ErrorLog_Create

ErrorLog_Destroy

ErrorLog_LogError

ErrorLog_GetErrors

ErrorLog_ShowErrorDialog

ErrorLog_ClearErrors

Example Program

ErrorLog_ExampleFrontPanel

ErrorLog_ExampleDiagram

This example shows the basic usage of the ErrorLog class. Once the object is constructed, you can use the same object from multiple loops in your program. You can also use the object reference to pass to sub-VI’s that you call. You can even pass a reference to a VI executing in parallel (although that is a little trickier).

Every place that can generate errors uses the Log Error VI to process the error. Each call to LogError includes a string to indicate the context of the code that generated the error. That ensures that all of the errors are collected, including a timestep and context, which can be very helpful later for finding the source of a problem.

You can use the Get Errors function in your main GUI loop to watch for errors to occur and light up an indicator. When the user sees that an error has occurred, he can hit the Show Errors button to bring up a dialog box that shows the history of errors.

Download

The example program is written in LabVIEW 8.5 with full access to the source. There is a simple example, as well as a more complex example that shows how to use multiple loops and customized a popup window.
Download: [Example] S5Tools ErrorLog Class.zip

This class has been saved in LabVIEW 8.5. Although password protected, the diagrams are present, so upgrading should be no problem. Download ErrorLog.llb and install into <LabVIEW>\user.lib\S5Tools
Download: ErrorLog.llb

The class is built with the Endevo GOOP Toolkit, version 2. The GOOP2 run-time is required to use the class. Download _goop2.llb and install into <LabVIEW>\vi.lib\addons
Download: _goop2.llb

One Comment

  1. Tim says:

    Hi Craig,

    I made a GOOP3 Singleton wrapper for your error logger and now it’s a drop in replacement for the “Clear Errors” but it actually logs! I also used your trick of using the “Get Errors” in the Event Timeout case where it updates an error indicator on the front panel and this is also a great place for sending the error to an error handler. I liked your idea of making it invisible if there are no errors but then showing it if there’s an error, and then clicking the indicator pops up the error dialog.

    Finally, professional quality error handling across all vi’s and through all hierarchy! Of course, the problem with that is I found some errors I didn’t know about and actually had to take the time to fix them :-)

    Thanks for sharing your error handler …

Leave a Reply