Tools.h++ Manual

18-4 104011 Tandem Computers Incorporated
18
Recoverable internal errors
If the cost of error detection is relatively low, then it starts to make sense to
detect an error even in a production version of the library. An example is a
bounds error in a linked list: the cost of walking the list will far exceed the cost
of detecting whether the index is in bounds. Hence, you can afford to check
for a bounds error on every access.
If an error is discovered, then the library will throw an exception inheriting
from
RWInternalErr
. Here’s an example from Tools.h++:
Distinguishing characteristics:
Similar to “Non-recoverable internal errors” (see above) except:
Cost of detection is low.
Detected in the debug and production version of the library.
Examples:
Attempt to use an invalid date
Bounds error in a linked list
Response:
Throw an exception inheriting from
RWInternalErr
.
// Find link “i”; the index must be in range:
RWIsvSlink* RWIsvSlist::at(size_t i) const
{
if (i >= entries())
RWTHROW( RWBoundsErr( RWMessage( RWTOOL_INDEX,
(unsigned)i,
(unsigned)entries()-1) ) );
register RWIsvSlink* link = head_.next_;
while (i--) link = link->next_;
return link;
}