Useful macros and functions for error checking and defensive programming. ASSERTs are only compiled if __WXDEBUG__ is defined, whereas CHECK macros stay in release builds.
Include files
<wx/debug.h>
::wxOnAssert
wxASSERT
wxASSERT_MSG
wxFAIL
wxFAIL_MSG
wxCHECK
wxCHECK_MSG
wxCHECK_RET
wxCHECK2
wxCHECK2_MSG
void wxOnAssert(const char* fileName, int lineNumber, const char* msg = NULL)
This function may be redefined to do something non trivial and is called whenever one of debugging macros fails (i.e. condition is false in an assertion).
wxASSERT(condition)
Assert macro. An error message will be generated if the condition is FALSE in debug mode, but nothing will be done in the release build.
Please note that the condition in wxASSERT() should have no side effects because it will not be executed in release mode at all.
See also: wxASSERT_MSG
wxASSERT_MSG(condition, msg)
Assert macro with message. An error message will be generated if the condition is FALSE.
See also: wxASSERT
wxFAIL()
Will always generate an assert error if this code is reached (in debug mode).
See also: wxFAIL_MSG
wxFAIL_MSG(msg)
Will always generate an assert error with specified message if this code is reached (in debug mode).
This macro is useful for marking unreachable" code areas, for example it may be used in the "default:" branch of a switch statement if all possible cases are processed above.
See also: wxFAIL
wxCHECK(condition, retValue)
Checks that the condition is true, returns with the given return value if not (FAILs in debug mode). This check is done even in release mode.
wxCHECK_MSG(condition, retValue, msg)
Checks that the condition is true, returns with the given return value if not (FAILs in debug mode). This check is done even in release mode.
This macro may be only used in non void functions, see also wxCHECK_RET.
wxCHECK_RET(condition, msg)
Checks that the condition is true, and returns if not (FAILs with given error message in debug mode). This check is done even in release mode.
This macro should be used in void functions instead of wxCHECK_MSG.
wxCHECK2(condition, operation)
Checks that the condition is true and wxFAIL and execute operation if it is not. This is a generalisation of wxCHECK and may be used when something else than just returning from the function must be done when the condition is false.
This check is done even in release mode.
wxCHECK2(condition, operation, msg)
This is the same as wxCHECK2, but wxFAIL_MSG with the specified msg is called instead of wxFAIL() if the condition is false.