Detecting Errors
How you detect an error obviously depends on the mechanism reporting it. In practical terms, this means:
- Return values
You determine whether a function failed by looking at its return code. This failure test is bound tightly to the act of calling the function; by making the call, you are implicitly checking its success. Whether or not you do anything with that information is up to you.
- Error status variables
After calling a function, you must inspect the error status variable. If it follows C’s
errnomodel of operation, you don’t actually need to test for errors after every single function call. First reseterrno, and then call any number of standard library functions back-to-back. Afterward, inspecterrno. If it contains an error ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access