NAME
OTC_Exception -
Base class for exceptions.
SYNOPSIS
#include <OTC/debug/excption.hh>
class OTC_Exception
{
public:
virtual ~OTC_Exception();
OTC_Exception(char const* theError=0);
OTC_Exception(
char const* theError,
char const* theFile,
u_int theLine
);
OTC_Exception(OTC_Exception const& theException);
inline char const* error() const;
inline char const* file() const;
inline u_int line() const;
virtual void display(ostream& outs) const;
static void throwException(OTC_Exception& theException);
static OTC_ThrowFunction setThrow(OTC_ThrowFunction theFunction);
};
CLASS TYPE
Concrete
DESCRIPTION
This class is intended to be the ultimate base class for all
exceptions. The class saves away information about the error which
has occurred. This information can be queried directly or a
message composing all the information can be dumped to an
ostream.
The class does not make copies of the character strings it is
given, nor does it delete them. Thus, character strings passed to
the constructor of the class should be literal strings, or
otherwise be guaranteed not to be deleted.
EXAMPLE
OTC_Exception exception("Underflow");
throw exception;
catch (OTC_Exception const& exception)
{
exception.display(cerr);
terminate();
}
INITIALISATION
OTC_Exception(char const* theError=0);
Saves theError as the description of the
type of error which has occurred. If
theError is 0, a description of
"Unknown error" is saved.
OTC_Exception(
char const* theError,
char const* theFile,
u_int theLine
);
Saves theError as the description of the
type of error which has occurred. If
theError is 0, a description of
"Unknown error" is saved. theFile
and theLine should be the name of the
file containing, and the line number in
the file, at which the code raising
the exception is located. These can be
generated using the preprocessor symbols
__FILE__ and __LINE__.
OTC_Exception(OTC_Exception const& theException);
Uses the description of the exception from
theException.
QUERY
inline char const* error() const;
Returns a description of the type of error
which has occurred.
inline char const* file() const;
Returns the name of file in which the code
raising the exception is located.
Will return 0 if the name of the file
is not known.
inline u_int line() const;
Returns the line number in the file at
which the code raising the exception is
located. Will return 0 if the line
in the file is not known.
DISPLAY
virtual void display(ostream& outs) const;
Dumps a message which composes together
all the information about the error on the
stream outs. This should be redefined
in derived class to first call the
base class version of the function, ie.,
OTC_Exception::display(), and then
dump out any additional information which
is kept in the derived class. The derived
class must terminate each line of
information with an endl.
THROWING AN EXCEPTION
static void throwException(OTC_Exception& theException);
Throws theException. If exceptions
are not supported by the compiler,
details of the exception are displayed
via the logger and terminate() called.
static OTC_ThrowFunction setThrow(OTC_ThrowFunction theFunction);
Set the function to be called when an
exception is thrown. This allows
something over than the default
action to be performed. For example,
a home grown exception could be
generated. The previously defined
throw function is returned.
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED