Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
It’s no coincidence that most modern languages created in the past 20 years use exceptions as their primary error reporting mechanism. Almost by definition, exceptions are for reporting exceptions to normal processing—also known as “errors,” defined in Item 70 as violations of preconditions, postconditions, and invariants. Like all error reporting, exceptions should not arise during normal successful operation.
We will use the term “status codes” to cover all forms of reporting status via codes (including return codes, errno, a GetLastError function, and other strategies to return or retrieve codes), and “error codes” specifically for status codes that signify errors. In C++, reporting errors via exceptions has clear advantages over reporting them via error codes, all of which make your code more robust: