NAME
OTCERR_AssertionFailure -
Exception class to be thrown for a failed assertion.
SYNOPSIS
#include <OTC/debug/asrtfail.hh>
class OTCERR_AssertionFailure : public OTC_Exception
{
public:
~OTCERR_AssertionFailure();
OTCERR_AssertionFailure(
char const* theFile,
u_int theLine,
char const* theCondition
);
OTCERR_AssertionFailure(
OTCERR_AssertionFailure const& theException
);
inline char const* condition() const;
void display(ostream& outs) const;
};
CLASS TYPE
Concrete
DESCRIPTION
This class is to be used, when you want to throw an exception for
an assertion failure. It is this exception which is thrown by
OTCLIB_ASSERT() when the condition fails. Typically, you would
not use this class directly but would use OTCLIB_ASSERT().
If used explicitly this class would be used in the following
way:
if (!(somePointer != 0))
{
OTCERR_AssertionFailure exception(
__FILE__,__LINE__,"somePointer != 0"
);
throw exception;
}
The prefered method of using this class though is to write:
OTCLIB_ASSERT(somePointer != 0);
When OTCLIB_ASSERT() is used it will be compiled out of code, if
the symbol NDEBUG is defined. Assertions would generally only be
used during development of software. If you are using makeit,
the symbol NDEBUG is automatically defined, when working in the
opt variant.
If a condition check is required to be permanently in code, ie.,
it is a precondition of the code that the condition always be
true; you should use the OTCERR_PreconditionFailure exception
class, or the OTCLIB_ENSURE() macro.
INITIALISATION
OTCERR_AssertionFailure(
char const* theFile,
u_int theLine,
char const* theCondition
);
Creates an exception class with type
description "Assertion Failure", for the
failed condition theCondition.
theFile, should be the name of the file
in which the exception is being raised,
supplied as __FILE__, and theLine,
should be the line in that file, supplied
as __LINE__.
OTCERR_AssertionFailure(OTCERR_AssertionFailure const& theException);
Uses the description of the exception from
theException.
QUERY
inline char const* condition() const;
Returns the condition that failed, and
resulted in the exception being raised.
DISPLAY
void display(ostream& outs) const;
Dumps a message which composes together
all the information about the error on the
stream outs.
SEE ALSO
OTC_Exception, OTCLIB_ENSURE, OTCLIB_ASSERT
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED