Showing results for 
Search instead for 
Did you mean: 

Proper API design and assigning status codes? What happens when a return is the same as a default value?

I've been working on interacting with an instrument via the manufacturer's DLL based API. Most calls return a status code like (0 Success, 1 Disconnected, 2 Error, etc, etc). This has proven to be problematic in some instances. For instance, if the API call simply doesn't actually work, the default value is returned, 0 Success, which is surely not good.


This has me thinking, what would be the proper way for designing an API status code system? My first thought is that the default value should probably always be the error code, that way it's safe whether or not the call succeeds. But I can't recall working with an API where that was the case, 0=error. Usually it seems -1 is, at least in the LabVIEW world. What do you think? 

0 Kudos
Message 1 of 3

How can it return something if it does not work? Is the "0" generated by your wrapper, for example?

0 Kudos
Message 2 of 3

Maybe negate error code + 8000 to get you to a standard custom user error?  (As an aside, -8000 to -8999 range is new to me for LabVIEW custom error range - I always thought the negative range was -5000 to -5999.  Did I remember incorrectly?)

(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 3