OTCLIB_ENSURE - macro to aid in program verfication

SYNOPSIS

#include <OTC/OTC.h>

OTCLIB_ENSURE(expression,description);

DESCRIPTION

The macro OTCLIB_ENSURE() can be used to aid in program verification. The macro is used to indicate the expectation that the expression is to be true at this point in the program. If expression is false, an exception of type OTCERR_PreconditionFailure will be thrown.

Note that OTCLIB_ENSURE() cannot be compiled out of code and should be used in preference to OTCLIB_ASSERT(), when you wish to ensure that the check will always be in the code. Although it cannot be compiled out of code, it is still not recommended that the expression have any side effects, which the program relies on to occur. This is suggested as someone in the future could unknowingly remove the precondition check altogether or replace it with an assertion failure. The result would be that the program may stop functioning correctly.

EXAMPLES

OTCLIB_ENSURE((TRUE == FALSE),"TRUE is not equal to FALSE");

FORMAT

If the exception is caught and the information it contains is dumped to the logger, the format of the output will be:

ERROR: Precondition failed
ERROR: Location: "_ensure.cc", line 33
ERROR: Condition: (TRUE == FALSE)
ERROR: Description: TRUE is not equal to FALSE

NOTES

The macro may be used in either C or C++ code.

A string literal should not be used as part of the condition as some preprocessors cannot handle converting to a string, a value which has a string in it.

SEE ALSO

OTCERR_PreconditionFailure, OTC_Logger