The following rules form a method to prevent such errors:
For example:
double sqrt( double x ) { require( x >= 0 ); // precondition: x may not be negative double result = ... ; // postcondition: check result value ensure ( abs( x - result * result ) <= DBL_EPSILON ); return result; }
This method is known as design-by-contract. For more information, see [DBC]
Checking of preconditions and postconditions may be included or excluded from the source independendly. See DEBUG.
Classes | |
class | Assertion |
base for design-by-contract assert exception. More... | |
class | DbcException |
design-by-contract exception. More... | |
Defines | |
#define | LOCATION __FILE__, __LINE__ |
(file,linenumber) tuple used by require() and ensure() macros. | |
#define | require(exp) |
require expression to be true, otherwise throw DbcException(REQUIRE). | |
#define | require_e(exp) |
require expression to be true, otherwise throw specified exception. | |
#define | ensure(exp) |
ensure expression to be true, otherwise throw DbcException(ENSURE). | |
#define | ensure_e(exp, ecxpt) |
ensure expression to be true, otherwise throw specified exception. | |
#define | NEVER_GET_HERE |
may not get here: throw DbcException(NEVER_GET_HERE). | |
#define | BASE_INVARIANT(base) base::invariant() |
execute base class invariant. | |
Functions | |
std::ostream & | operator<< (std::ostream &stream, Rulbus::StdExceptionCref rhs) |
write exception to stream. |