An Objection Class for Rudimentary Error Handling - Objection(C++)

An Objection Class for Rudimentary Error Handling - Objection(C++)

This section describes an early alternative to C++ exception handling. Now that exception handling is implemented in the UnixWare compiler, it should be used in preference to objections. However, this section is still included in this document because Standard Components uses objections internally.

One common method for handling error conditions is to set an error flag or return a suspicious value when something goes wrong. The client programmer is then expected to check this value to make sure that everything is fine. Unfortunately, this is not always reasonable or possible. For example, a C++ String library user should not have to check the length of each String created to see if memory was obtained. Also, checking a return value is impossible for some functions invoked via overloaded operators. An alternative solution in these cases is to abort or exit the client program when an error occurs. This can be an unacceptable choice when the program is large or needs to do specific cleanup before exiting. The last alternative is to perform some sort of recovery action. But this can be dangerous because the programmer has no warning that something ``unusual'' has happened; and the recovery action may not be what is really required. One good solution is to let the client choose between these alternatives.

The purpose of this tutorial is to describe a simple class, called Objection, which can be used to implement rudimentary error handling. Software authors can use Objections to catch errors in the use of their software and execute actions which the client has associated with the error. Clients of the software can use Objections to associate actions with the errors which can occur. This is not exception handling. Objections do not mimic exception handling or solve the problems which exceptions solve. They simply provide an interim method for handling errors until exception handling is in universal use as part of the language.

Objections can be useful for handling errors in third party software of any kind. However, for the purposes of this tutorial, we will assume that the software developer is the author of a general purpose library and the software client is the programmer who uses this library. The next two sections describe in more detail how Objections can be used by the library author and the client programmer.

Next topic: Objections for the Software Author

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005