An abstract data type will often have situations in which it is not meaningful to apply certain operations. For the stack, attempting to pop an empty stack or attempting to remove the top-most element from an empty stack are two such abnormal situations. The basic problem is that these operations possess domain values with no corresponding range value and they are partial in the sense described in sections 5.2.5 and 2.5.4. It is vital that an algebraic specification should not only formally describe the behaviour of the operations of an abstract data type for normal situations but also in these abnormal or exceptional ones.
The problem of dealing with errors in algebraic specifications is not as straightforward as might be supposed. Some of the methods described in the early literature for treating error values were not mathematically sound and in an attempt to put error handling onto a rigorous footing, techniques were developed which turned ``a little local difficulty'' into a ``major mathematical mayhem''. This particular aspect of algebraic specification is, however, not as awkward as some critics of the approach would have us believe.
To date, we have handled errors by the seemingly simple expedient
of introducing an additional constant error value of the
appropriate sort. In the case of Stack, for example as
given in Fig. 8.2, we introduced the nullary operations
to accommodate the outcomes of applying pop and top to an empty stack. This approach was adopted initially at the outset to allow the reader to gain an immediate foothold onto algebraic specification without getting bogged down with the subtleties of error handling. It is now time to appraise the implications of the use of error values.