Don’t ignore API function return values


Most API functions will return a particular value which represents an error. You should test for these values every time you call the API function. If you don’t want want to clutter your code with error-testing, then wrap the API call in another function (do this when you are thinking about portability, too) which tests the return value and either asserts, handles the problem, or throws an exception. The above example of Open Data File is a primitive way of wrapping fopen with error-checking code which throws an exception if fopen fails.

No comments:

Post a Comment