1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of global functions
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
8 /** @addtogroup group_funcmacro_debug */
12 Exits the program immediately.
14 This is a simple wrapper for the standard abort() function which is not
15 available under all platforms (currently only Windows CE doesn't provide
25 Preprocessor symbol defining the level of debug support available.
27 This symbol is defined to 1 by default meaning that asserts are compiled in
28 (although they may be disabled by a call to wxDisableAsserts()). You may
29 predefine it as 0 prior to including any wxWidgets headers to omit the
30 calls to wxASSERT() and related macros entirely in your own code and you
31 may also predefine it as 0 when building wxWidgets to also avoid including
32 any asserts in wxWidgets itself.
34 Alternatively, you may predefine it as 2 to include wxASSERT_LEVEL_2() and
35 similar macros which are used for asserts which have non-trivial run-time
36 costs and so are disabled by default.
47 Compatibility macro indicating presence of debug support.
49 This symbol is defined if wxDEBUG_LEVEL is greater than 0 and undefined
57 Type for the function called in case of assert failure.
59 @see wxSetAssertHandler()
61 typedef void (*wxAssertHandler_t
)(const wxString
& file
,
68 Assert macro. An error message will be generated if the condition is @false in
69 debug mode, but nothing will be done in the release build.
71 Please note that the condition in wxASSERT() should have no side effects
72 because it will not be executed in release mode at all.
74 This macro should be used to catch (in debug builds) logical errors done
77 @see wxASSERT_MSG(), wxCOMPILE_TIME_ASSERT()
81 #define wxASSERT( condition )
84 Assert macro for expensive run-time checks.
86 This macro does nothing unless wxDEBUG_LEVEL is 2 or more and is meant to
87 be used for the assertions with noticeable performance impact and which,
88 hence, should be disabled during run-time.
90 If wxDEBUG_LEVEL is 2 or more, it becomes the same as wxASSERT().
94 #define wxASSERT_LEVEL_2( condition )
97 Assert macro with a custom message for expensive run-time checks.
99 If wxDEBUG_LEVEL is 2 or more, this is the same as wxASSERT_MSG(),
100 otherwise it doesn't do anything at all.
102 @see wxASSERT_LEVEL_2()
106 #define wxASSERT_LEVEL_2_MSG( condition, msg)
110 This macro results in a @ref wxCOMPILE_TIME_ASSERT "compile time assertion failure"
111 if the size of the given @c type is less than @c size bits.
113 This macro should be used to catch (in debug builds) logical errors done
116 You may use it like this, for example:
119 // we rely on the int being able to hold values up to 2^32
120 wxASSERT_MIN_BITSIZE(int, 32);
122 // can't work with the platforms using UTF-8 for wchar_t
123 wxASSERT_MIN_BITSIZE(wchar_t, 16);
128 #define wxASSERT_MIN_BITSIZE( type, size )
131 Assert macro with message.
132 An error message will be generated if the condition is @false.
134 This macro should be used to catch (in debug builds) logical errors done
137 @see wxASSERT(), wxCOMPILE_TIME_ASSERT()
141 #define wxASSERT_MSG( condition, message )
144 Checks that the condition is @true, returns with the given return value if
145 not (stops execution in debug mode). This check is done even in release mode.
147 This macro should be used to catch (both in debug and release builds) logical
148 errors done by the programmer.
152 #define wxCHECK( condition, retValue )
155 Checks that the condition is @true, returns with the given return value if
156 not (stops execution in debug mode). This check is done even in release mode.
158 This macro may be only used in non-void functions, see also wxCHECK_RET().
160 This macro should be used to catch (both in debug and release builds) logical
161 errors done by the programmer.
165 #define wxCHECK_MSG( condition, retValue, message )
168 Checks that the condition is @true, and returns if not (stops execution
169 with the given error message in debug mode). This check is done even in
172 This macro should be used in void functions instead of wxCHECK_MSG().
174 This macro should be used to catch (both in debug and release builds) logical
175 errors done by the programmer.
179 #define wxCHECK_RET( condition, message )
182 Checks that the condition is @true, and if not, it will wxFAIL() and
183 execute the given @c operation if it is not. This is a generalisation of
184 wxCHECK() and may be used when something else than just returning from the
185 function must be done when the @c condition is @false. This check is done
186 even in release mode.
188 This macro should be used to catch (both in debug and release builds) logical
189 errors done by the programmer.
193 #define wxCHECK2(condition, operation)
196 This is the same as wxCHECK2(), but wxFAIL_MSG() with the specified
197 @c message is called instead of wxFAIL() if the @c condition is @false.
199 This macro should be used to catch (both in debug and release builds) logical
200 errors done by the programmer.
204 #define wxCHECK2_MSG( condition, operation, message )
207 Using wxCOMPILE_TIME_ASSERT() results in a compilation error if the
208 specified @c condition is @false. The compiler error message should include
209 the @c message identifier - please note that it must be a valid C++
210 identifier and not a string unlike in the other cases.
212 This macro is mostly useful for testing the expressions involving the
213 @c sizeof operator as they can't be tested by the preprocessor but it is
214 sometimes desirable to test them at the compile time.
216 Note that this macro internally declares a struct whose name it tries to
217 make unique by using the @c __LINE__ in it but it may still not work if you
218 use it on the same line in two different source files. In this case you may
219 either change the line in which either of them appears on or use the
220 wxCOMPILE_TIME_ASSERT2() macro.
222 Also note that Microsoft Visual C++ has a bug which results in compiler
223 errors if you use this macro with 'Program Database For Edit And Continue'
224 (@c /ZI) option, so you shouldn't use it ('Program Database' (@c /Zi) is ok
225 though) for the code making use of this macro.
227 This macro should be used to catch misconfigurations at compile-time.
229 @see wxASSERT_MSG(), wxASSERT_MIN_BITSIZE()
233 #define wxCOMPILE_TIME_ASSERT( condition, message )
236 This macro is identical to wxCOMPILE_TIME_ASSERT() except that it allows
237 you to specify a unique @c name for the struct internally defined by this
238 macro to avoid getting the compilation errors described for
239 wxCOMPILE_TIME_ASSERT().
241 This macro should be used to catch misconfigurations at compile-time.
245 #define wxCOMPILE_TIME_ASSERT2(condition, message, name)
248 Disable the condition checks in the assertions.
250 This is the same as calling wxSetAssertHandler() with @NULL handler.
256 void wxDisableAsserts();
259 @def wxDISABLE_ASSERTS_IN_RELEASE_BUILD
261 Use this macro to disable asserts in release build when not using
264 By default, assert message boxes are suppressed in release build by
265 wxIMPLEMENT_APP() which uses this macro. If you don't use wxIMPLEMENT_APP()
266 because your application initializes wxWidgets directly (e.g. calls
267 wxEntry() or wxEntryStart() itself) but still want to suppress assert
268 notifications in release build you need to use this macro directly.
270 @see wxDISABLE_DEBUG_SUPPORT()
276 #define wxDISABLE_ASSERTS_IN_RELEASE_BUILD() wxDisableAsserts()
279 Will always generate an assert error if this code is reached (in debug mode).
280 Note that you don't have to (and cannot) use brackets when invoking this
284 if (...some condition...) {
289 This macro should be used to catch (in debug builds) logical errors done
299 Will always generate an assert error with specified message if this code is
300 reached (in debug mode).
302 This macro is useful for marking "unreachable" code areas, for example it
303 may be used in the "default:" branch of a switch statement if all possible
304 cases are processed above.
306 This macro should be used to catch (in debug builds) logical errors done
313 #define wxFAIL_MSG( message )
316 Returns @true if the program is running under debugger, @false otherwise.
318 Please note that this function is currently only implemented for Win32 and
319 always returns @false elsewhere.
323 bool wxIsDebuggerRunning();
326 Sets the function to be called in case of assertion failure.
328 The default assert handler forwards to wxApp::OnAssertFailure() whose
329 default behaviour is, in turn, to show the standard assertion failure
330 dialog if a wxApp object exists or shows the same dialog itself directly
333 While usually it is enough -- and more convenient -- to just override
334 OnAssertFailure(), to handle all assertion failures, including those
335 occurring even before wxApp object creation of after its destruction you
336 need to provide your assertion handler function.
338 This function also provides a simple way to disable all asserts: simply
339 pass @NULL pointer to it. Doing this will result in not even evaluating
340 assert conditions at all, avoiding almost all run-time cost of asserts.
342 Notice that this function is not MT-safe, so you should call it before
343 starting any other threads.
345 The return value of this function is the previous assertion handler. It can
346 be called after any pre-processing by your handler and can also be restored
347 later if you uninstall your handler.
350 The function to call in case of assertion failure or @NULL.
352 The previous assert handler which is not @NULL by default but could be
353 @NULL if it had been previously set to this value using this function.
359 wxAssertHandler_t
wxSetAssertHandler(wxAssertHandler_t handler
);
362 Reset the assert handler to default function which shows a message box when
365 This can be useful for the applications compiled in release build (with @c
366 NDEBUG defined) for which the asserts are by default disabled: if you wish
367 to enable them even in this case you need to call this function.
373 void wxSetDefaultAssertHandler();
376 Generate a debugger exception meaning that the control is passed to the
377 debugger if one is attached to the process.
379 Otherwise the program just terminates abnormally.
381 If @c wxDEBUG_LEVEL is 0 (which is not the default) this function does