Open CASCADE Technology  7.7.0
Data Structures | Macros | Functions
Standard_Assert.hxx File Reference

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...

#include <Standard_ProgramError.hxx>

Data Structures

struct  Standard_Static_Assert< condition >
 Static assert – empty default template. More...
 
struct  Standard_Static_Assert< true >
 Static assert – specialization for condition being true. More...
 

Macros

#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. More...
 
#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) More...
 
#define Standard_ASSERT_INVOKE(theDesc)   Standard_ASSERT_INVOKE_(always, theDesc)
 Raise debug message. More...
 
#define Standard_STATIC_ASSERT(theExpr)   Standard_Static_Assert<theExpr>::assert_ok();
 Cause compiler error if argument is not constant expression or evaluates to false. More...
 

Functions

void Standard_ASSERT_DO_NOTHING ()
 

Detailed Description

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.

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:

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 _DEBUG: 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:

The second argument (message) should be string constant ("...").

The Standard_STATIC_ASSERT macro is to be used for compile time checks. To use this macro, write:

Standard_STATIC_ASSERT(const_expression);

If const_expression is false, a compiler error occurs.

The macros are formed as functions and require semicolon at the end.

Macro Definition Documentation

◆ Standard_ASSERT

#define Standard_ASSERT (   theExpr,
  theDesc,
  theAction 
)
Value:
if (!(theExpr)) { theAction; } \
void Standard_ASSERT_DO_NOTHING()
Definition: Standard_Assert.hxx:70

◆ Standard_ASSERT_INVOKE

#define Standard_ASSERT_INVOKE (   theDesc)    Standard_ASSERT_INVOKE_(always, theDesc)

Raise debug message.

◆ Standard_ASSERT_INVOKE_

#define Standard_ASSERT_INVOKE_ (   theExpr,
  theDesc 
)    Standard_ASSERT_DO_NOTHING()

◆ Standard_ASSERT_RAISE

#define Standard_ASSERT_RAISE (   theExpr,
  theDesc 
)
Value:
Standard_ASSERT(theExpr, theDesc, throw Standard_ProgramError( \
"*** ERROR: ASSERT in file '" __FILE__ "': \n" theDesc " (" #theExpr ")" ) )
#define Standard_ASSERT(theExpr, theDesc, theAction)
Definition: Standard_Assert.hxx:142

Raise exception (Standard_ProgramError) with the provided message.

◆ Standard_ASSERT_RETURN

#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)

◆ Standard_ASSERT_SKIP

#define Standard_ASSERT_SKIP (   theExpr,
  theDesc 
)    theExpr

◆ Standard_ASSERT_VOID

#define Standard_ASSERT_VOID (   theExpr,
  theDesc 
)    Standard_ASSERT_DO_NOTHING()

◆ Standard_STATIC_ASSERT

#define Standard_STATIC_ASSERT (   theExpr)    Standard_Static_Assert<theExpr>::assert_ok();

Cause compiler error if argument is not constant expression or evaluates to false.

Function Documentation

◆ Standard_ASSERT_DO_NOTHING()

void Standard_ASSERT_DO_NOTHING ( )
inline