Chapter 12 Exceptions

There are three categories of outcomes that can occur when a function is called during program execution: normal execution, erroneous execution, or abnormal execution. Each category is described below.

Normal execution

The function may execute normally and return. Some functions return a result code to the caller, which indicates the outcome of the function. The possible result codes are strictly defined for the function and represent the range of possible outcomes of the function. The result code can indicate success or failure or can even indicate a particular type of failure that is within the normal range of expectations. For example, a file-status function can return a code that indicates that the file does not exist. Note that the term “error code” is not used since a result code represents one of many expected outcomes.

Erroneous execution

The caller makes some mistake in passing arguments to the function or calls the function in an inappropriate context. This situation causes an error, and it should be detected by an assertion during program development. (For more information on assertions, see page 288).

Abnormal execution

Abnormal execution includes situations where conditions outside the program's control are influencing the outcome of the function, such as low memory or I/O errors. Abnormal situations should be handled by catching and throwing exceptions.