Kinds of Errors
The first thing a useful error handler needs to know is what kind of error it is dealing with. The Essential Tools Module approach is to classify errors as internal or external, depending on whether or not they can reasonably be predicted in advance by the programmer. In the Essential Tools Module, an internal error throws an exception of type RWInternalErr, and an external error throws an exception of type RWExternalErr. In the DB Interface Module, however, database errors are also possible. To simplify the situation, we have adopted the policy that all errors are external errors. This means that:
*The type of exception thrown by RWDBStatus::raise() is RWExternalErr. Note that some of the Essential Tools Module classes used by the DB Interface Module could still throw an RWInternalErr.
*Your application logic needs to distinguish between errors from databases and errors from the DB Interface Module.
The errorCode() member function of RWDBStatus tells you the kind of error you're dealing with; for a list of error codes, see the entry for RWDBStatus in the SourcePro API Reference Guide. Of these, the codes vendorLib, serverError, and serverMessage indicate database errors or events, while the remaining error messages are generated by the DB Interface Module itself. But even though there are many more error codes generated by the DB Interface Module, our experience indicates that most errors in database applications are database errors. In order to distinguish database errors from other errors, the first part of our error handler might look like this:
 
void errorHandler(const RWDBStatus& status) {
RWDBStatus::ErrorCode code = status.errorCode();
if (code == RWDBStatus::vendorLib ||
code == RWDBStatus::serverError ||
code == RWDBStatus::serverMessage) {
// handle database error
}
else { // raise an exception
if (!status.isValid()) {
status.raise();
}
}
}