This header file defines a set of ASSERT macros intended for use in algorithms for debugging purposes and as a tool to organise checks for abnormal situations in the uniform way.
More...
Defines |
#define | Standard_ASSERT_INVOKE_(theExpr, theDesc) Standard_ASSERT_DO_NOTHING() |
#define | Standard_ASSERT(theExpr, theDesc, theAction) |
#define | Standard_ASSERT_SKIP(theExpr, theDesc) theExpr |
#define | Standard_ASSERT_VOID(theExpr, theDesc) Standard_ASSERT_DO_NOTHING() |
#define | Standard_ASSERT_RAISE(theExpr, theDesc) |
| Raise exception (Standard_ProgramError) with the provided message.
|
#define | Standard_ASSERT_RETURN(theExpr, theDesc, theReturnValue) Standard_ASSERT(theExpr, theDesc, return theReturnValue) |
| Return from the current function with specified value (empty if the function returns void)
|
#define | Standard_ASSERT_INVOKE(theDesc) Standard_ASSERT_INVOKE_(always, theDesc) |
| Raise debug message.
|
Functions |
void | Standard_ASSERT_DO_NOTHING () |
In contrast to C assert() function that terminates the process, these macros provide choice of the action to be performed if assert failed, thus allowing execution to continue when possible. Except for the message for developer that appears only in Debug mode, the macros behave in the same way in both Release and Debug modes.
The ASSERT macros differ in the way they react on a wrong situation:
- Standard_ASSERT_RAISE: raises exception Standard_ProgramError
- Standard_ASSERT_RETURN: returns specified value (last argument may be left empty to return void)
- Standard_ASSERT_SKIP: does nothing
- Standard_ASSERT_VOID: does nothing; even does not evaluate first arg when in Release mode
- Standard_ASSERT_INVOKE: causes unconditional assert
- Standard_ASSERT: base macro (used by other macros); does operation indicated in argument "todo"
The assertion is assumed to fail if the first argument is evaluated to zero (false). The first argument is evaluated by all macros except Standard_ASSERT_VOID which does not evaluate first argument when in Release mode. The mode is triggered by preprocessor macro DEB: if it is defined, Debug mode is assumed, Release otherwise.
In debug mode, if condition is not satisfied the macros call Standard_ASSERT_INVOKE_ which:
- on Windows (under VC++), stops code execution and prompts to attach debugger to the process immediately.
- on POSIX systems, prints message to cerr and raises signal SIGTRAP to stop execution when under debugger (may terminate the process if not under debugger).
The second argument (message) should be string constant ("...").
The macros are formed as functions and require semicolon at the end.