Check the Return Value
The dominance of object-oriented design has not eliminated the use of the procedural models of API design. Use of and adaptation to older but ubiquitous procedural APIs such as POSIX suggest using returns and/or the global errno to communicate meaningful values corresponding to error conditions. Many POSIX calls, such as open(2),1 return an integer -1 on error and use a range of errno values for the error details.
1. See http://pubs.opengroup.org/onlinepubs/000095399/functions/open.html.
We have explored various ways to inject values into our code for testing purposes. We use those same techniques to inject procedural error codes. Commonly, we will thinly encapsulate procedural system APIs such as POSIX such that they ...
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