Example Code

Run-time error checking: a personal solution

Code and Documents

Attachment

Overview

User developed run-time error checking tools with increased messaging and level of detail.

Note: This is not a complete a functional sample code: instead,  it is intended as some suggestions to be integrated and eventually adapted to your actual application and programming style and standards.

Description

With the exception of some high-level operators that are aware of internal software specifications, the user is interested to know that a serious error has raised and that the program is not working correctly; date and time the error raised can be useful too; advanced users and the programmer are more interested to function / source file / type of error and line where the error occurred. All of these informations could be either displayed on the screen or saved to disk (or both).

This implementation is basically an extension / adaptation of the good errChk and nullChk macros already defined in the programmer's toolbox. These extended macros adds the information about the line the error raised. Additionally, similar macros were developed to handle several different types of errors that can occur at runtime: file I/O operations, serial communications, DAQ acquistion / generation of signals, etc... Macros were added to handle errors that can arise while executing a loop that needs to be completed in a proper way.

To display error information, one solution would be to use a MessagePopup with all relevant information within the originating function. When executing multithreaded applications this may not be an optimal solution as the program cannot simply be halted waiting for user action. In this case all information must be conveyed out of the execution thread and passed to the main thread, where the message can be prompted without disturbing the running threads.

Steps to Implement Code

1. Download and extract zip folder contents

2. Include files in project

3. Reference header file.

Requirements

Software

-LabWindows CVI

**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
ebalci
Active Participant
Active Participant
on

copy-paste typo

In the code block given below in the article, all inputs "daqerr" to ErrorMessage function as error code.

Shouldn't it differ for each type of error?

...

ErrorMessage (daqerr, ERRDAQ, line, __FUNCTION__, __FILE__)

else if (error < 0)

ErrorMessage (daqerr, ERRGEN, line, __FUNCTION__, __FILE__)

else if (comerr < 0)

ErrorMessage (daqerr, ERRCOM, line, __FUNCTION__, __FILE__)

else if (ioerr < 0)

ErrorMessage (daqerr, ERRIO, line, __FUNCTION__, __FILE__)

...

S. Eren BALCI
IMESTEK
BetaCommunityCo
Member
Member
on

copy-paste typo

Thanks Eren for the advise: of course you are right and I have corrected the source code according to it. :)

Christian_L
Active Participant
Active Participant
on

Can you move the code out of the text of the main document and into a separate download file. The main document is very unreadable, and should not contain long sections of code. Any code in the main documented should be formatted to read easily.

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
Contributors