The definition of an exception is based on the observation that each
procedure has a
precondition, a set of circumstances for which it will terminate "normally". An exception handling mechanism allows the procedure to
raise an exception if this precondition is violated, an unavailable resource (like a missing file, a network drive error, or out-of-memory errors), or that the routine has detected a normal condition that requires special handling, e.g., attention, end of file. Social pressure is a major influence on the scope of exceptions and use of exception-handling mechanisms, i.e. "examples of use, typically found in core libraries, and code examples in technical books, magazine articles, and online discussion forums, and in an organization’s code standards". Exception handling solves the
semipredicate problem, in that the mechanism distinguishes normal return values from erroneous ones. In languages without built-in exception handling such as C, routines would need to signal the error in some other way, such as the common
return code and
errno pattern. The term "exception" is preferred to "error" because it does not imply that anything is wrong - a condition viewed as an error by one procedure or programmer may not be viewed that way by another. when in fact raising the exception may be a normal and usual situation in the program. For example, suppose a lookup function for an
associative array throws an exception if the key has no value associated. Depending on context, this "key absent" exception may occur much more often than a successful lookup. == History ==