Exception handling

We define an Exception to be the occurrence of an abnormal condition during execution of a program. Generally, an exception is caused by a failure which was caused by an error. Exception handling mechanisms have been added to some programming languages and many embedded systems. These mechanism are based around the requirement for well defined behavior such as atomicity. A piece of software must succeed or fail. Thus an exception must provide only two possibilities:
  1. Tidy up and report failure to a higher authority
  2. Retry (perhaps another way).
We can further refine our idea of exceptions (especially in distributed systems) by observing that there are 4 places an exception can occur:
  1. An object is being asked incorrectly to do something it cannot
  2. There is a fault in the object
  3. The object invokes an operation in another which is faulty.
  4. There is a communications failure
Case 1 can be dealt with by pre-conditions on operations preventing this object being corrupted by faults elsewhere. Case 2 must be dealt with by raising a higher level exception (and will require maintenance). Case 3 requires a retry mechanism where we may choose an alternate if possible. Case 4 may be dealt with by retry to an alternate. Implementing exception handling is hard. It is only just being introduced to C++ at the time of writing.