LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I do Error trapping..

I have inherited a large CVI project that has almost no error handling. I know there are these IVI macros that allow me to encapsulate a function call, so that when/if an error is thrown in the function I can log that error to a file (or whatever).

Has anyone done something like this? I basically want to capture any errors that are thrown without having to add a bunch of extra code to the project. How do I go about implementing it?

Kindest,
Warren
0 Kudos
Message 1 of 2
(3,193 Views)
For an example of error trapping macros you can look at errChk and NullChk macros defined in the programmer's toolbox of CVI (look into \toolslib\toolbox\toolbox.h): these macros detect an error code as a return code for a function and jump to an Error label that you must define in your code.
I have used them and found useful for example when reading parameters file (I use .INI files for them). Here an example of use:

int error = 0;
IniText T = 0;

nullChk (T = Ini_New (0));
errChk (Ini_ReadFromFile (T, "application.par"));
errChk (Ini_GetInt (T, section, item, &val));

Error:
if (T) Ini_Dispose (T);
if (error < 0) {
// Here put your error managing code
}
return error;

Roberto


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?
0 Kudos
Message 2 of 2
(3,193 Views)