Tools.h++ Manual
104011 Tandem Computers Incorporated 18-7
18
Note – Note that the line between an internal and external error can sometimes
be fuzzy. For example, the rules could say “don’t give me an invalid date” and
then the programmer would be responsible for detecting a bad date before
using a Tools.h++ routines. Of course, this is a lot of work and probably the
reason why you bought the library in the first case: the
RWDate
object is
probably in a much better position than you to detect invalid dates.
In theory, the response to an external error is either to throw an exception or to
provide a test for object validity. It should never abort the program. However,
in practice, exceptions have not been widely adopted by compilers and so
Tools.h++ provides an opportunity to either test for a status value or to recover
in an error handler.
Here’s an example:
18.3 Exception architecture
When an exception is thrown a throw operand is passed. The type of the throw
operand determines which handlers can catch it. Tools.h++ uses the following
hierarchy for throw operands:
RWDate date;
while (1)
{
cout << “Give a date: “;
cin >> date;
if (date.isValid()) break;
cout << “You entered a bad date; try again\n”;
}
xmsg
RWxmsg
RWInternalErr
RWBoundsErr
RWExternalErr
RWFileErr
RWStreamErr
xalloc
RWxalloc