LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a range of error codes reserved for user defined error codes?

I would like to create my own error codes for a CVI dll but I want to make sure I don't use error codes already defined for something else. Is there a range reserved for such use?

Samee thing for warnings (errorcode > 0)

 

Thanks

0 Kudos
Message 1 of 7
(5,426 Views)

I use positive numbers for my error codes.

Not only CVI but also almost all other 3rd party libraries use negative numbers for error codes.

So I preferred positive numbers to avoid confusion when generating corresponding error messages.

 

I define various error check macros for my functions and 3rd party libraries, so that I do not have to write if-claueses after each library function call.

Those macros look like this: ChkErr(fcall) if ((iErrCode = (fcall)) != 0) goto ABORT

 

I recommend using that aproach, it makes the code clear and well covered for errors.

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 7
(5,419 Views)
That sounded like a good solution to me too except that CVI uses positive error codes for warnings, and negative error codes for exception, so there might still be some conflicts there too depending on what range of posisitve numbers CVI uses for warnings.
0 Kudos
Message 3 of 7
(5,416 Views)

I have never found a positive mention of a "safe" range of error codes available for user-defined error conditions, but I can suggest you some source of informations.

 

First of all, every library has its specific list of error codes, usually listed in the relative include file. All these error codes are listed in the online help too (search for "error codes" in the index tab of the help).

 

Second, GetGeneralErrorString () is a function that can be used to trap errors of the following libraries with a unique error function:

  • User Interface Library
  • Easy I/O instrument driver
  • Toolbox instrument driver
  • ActiveX Library
  • DIAdem Connectivity Library
  • .NET Library
  • DataSocket instrument driver
  • Network Variable Library
  • Real-Time Utility Library
  • TDM Streaming Library
  • UDP Support Library

This means that the error codes from this libraries do not overlap, so you could derive from its code some ranges not used by these libraries.

 

Nevertheless, there is not a single function for error trapping: every library has its proper list of error codes and a function to decode them in human readable form, andthere is no guarantee that these ranges does not overlap. It's up to you to trap errors from every function in the proper way.

 



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 4 of 7
(5,411 Views)

I run into this all the time, some think that the errors must be unique.  Since there are so many, and no single entity that would be in position to control the numbering in all cases, I tell developers to not even try, and as Roberto says provide a function    string = xxxxGetErrorString (error code); so that the calling code can at least get a unique human readable message is he chooses to handle the error in the calling context.

 

It's kindof like handling exception I think.  There's a rule of thumb in exception handling that says unless the exception is handled at the lowest level (where first encountered, without re-throwing it) then it's unlikey to get properly handled at all.  So if an error code is returned and you chose to not react/log/interpret it where it is uniquely known, then it doesn't much matter, it wasn't that important 😉

 

In today's era of large capacities (well, on PC's at least)  there's usually room for a good sized log file that can hold human-readable strings rather than (potentially overlapping) error codes.

 

Menchar

0 Kudos
Message 5 of 7
(5,366 Views)

Of course it is not possible to use the positive numbers blindly.

You need to check the libraries you use, but positive numbers are less likely to overlap with most other libraries' error codes. 

 

I am in the middle of a large DLL project I'm writing in CVI (bunch of functions to be called by a TestStand sequence from this dll).

I prefered to set an error code as the return value of almost every function. I used 0 (zero) for no error and non-zero values (positive or negative depending on whether they are generated by me or another library) for errors.

 

I used passed-by-reference variables to output any values and I put an error message parameter at the end of my parameter list of these functions to output any error message generated by either my function (if the error code is positive) or the other library function. (For TestStand users: I passed this error message to Step.Result.ReportText whenever possible, if the output values needs comparison I added no-adapter numeric limit steps just after the function call)

 

If an error code is returned from any function I passed the control with the goto's in the macros (I mentioned in my previous post) to the end of the function where the error message is determined or just to return the error code to the calling function which will eventually determine the error message.

 

Using this approach I got pretty good error coverage and good error logging. And all functions together look like a consistent library with error codes returned and error messages output as parameters.

 

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 6 of 7
(5,345 Views)

I think this is a good suggestion, so I've just filled a product suggestion in CVI Idea Exchange.

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 7 of 7
(4,837 Views)