#include <OTC/debug/precfail.hh> class OTCERR_PreconditionFailure : public OTC_Exception {
public:
~OTCERR_PreconditionFailure();
OTCERR_PreconditionFailure( char const* theFile, u_int theLine, char const* theCondition, char const* theDescription );
OTCERR_PreconditionFailure( OTCERR_PreconditionFailure const& theException );
inline char const* condition() const;
inline char const* description() const;
void display(ostream& outs) const;
};
OTCLIB_ENSURE()
when the condition fails. Typically, you would
not use this class directly, but would use OTCLIB_ENSURE()
.
If used explicitly this class would be used in the following
way:
if (!(somePointer != 0))
{
OTCERR_PreconditionFailure exception(
__FILE__,__LINE__,"somePointer != 0","some description"
);
throw exception;
}
The preferred method of using this class, is to write:
OTCLIB_ENSURE((somePointer != 0),"some description");
OTCLIB_ENSURE()
cannot be compiled out of code. If a condition
check is only required during development the OTCLIB_ASSERT()
macro, which can be compiled out of code by defining NDEBUG
should be used.
OTCERR_PreconditionFailure(
char const* theFile,
u_int theLine,
char const* theCondition,
char const* theDescription
);
"Precondition Failure"
, for
the failed condition theCondition
.
theFile
should be the name of the file;
supplied as __FILE__
, and theLine
should be the line in the file; supplied
as __LINE__
. theDescription
should be
an English description of the failure
which has occurred.
OTCERR_PreconditionFailure(
OTCERR_PreconditionFailure const& theException
);
theException
.
inline char const* condition() const;
inline char const* description() const;
void display(ostream& outs) const;
outs
.
OTC_Exception
, OTCLIB_ASSERT
, OTCLIB_ENSURE