#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;
};
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.
OTCERR_AssertionFailure(
char const* theFile,
u_int theLine,
char const* theCondition
);
"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);
theException
.
inline char const* condition() const;
void display(ostream& outs) const;
outs
.
OTC_Exception
, OTCLIB_ENSURE
, OTCLIB_ASSERT