xtd 0.2.0
Loading...
Searching...
No Matches

◆ cassert_

#define cassert_ (   ...)

#include <xtd.core/include/xtd/diagnostics/debug.h>

Checks for a condition; if the condition is false, displays a message box that shows the call stack.

Inheritance
xtd::static_objectxtd::diagnostics::debug
Header
#include <xtd/diagnostics/debug>
Library
xtd.core
Parameters
conditionThe conditional expression to evaluate. If the condition is true, a failure message is not sent and the message box is not displayed.
message(optional) The brief message to send to the xtd::diagnostics::debug::listeners collection.
detail_message(optional) The detail message to send to the xtd::diagnostics::debug::listeners collection.
Usage
This assert can only call by xtd::diagnostics::debug and xtd::diagnostics::trace like this :
  • xtd::diagnostics::debug::cassert_();
  • xtd::diagnostics:trace::cassert_();
Examples
The following example shows how to use xtd::diagnostics::debug::cassert_ method.
#include <xtd/diagnostics/debug>
#include <xtd/console>
using namespace xtd;
using namespace xtd::diagnostics;
auto main() -> int {
// Uncomment following lines to remove assert dialog
//for (auto listener : debug::listeners())
// if (is<default_trace_listener>(listener))
// as<default_trace_listener>(listener)->assert_ui_enabled(false);
auto index = 0;
console::write_line("Start application");
debug::cassert_(index > 0);
console::write_line("End application");
}
// This code produces the following output :
//
// > If user clicks assert dialog 'Abort' button:
// Start application
//
// > If user clicks assert dialog 'Retry' button:
// Start application
// > Break the debugger on file debug_cassert.cpp line 12.
// > If user choose continue running after break.
// End application
//
// > If user clicks assert dialog 'Ignore' button:
// Start application
// End application
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.h:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Examples
The following example shows how to use xtd::diagnostics::trace::cassert_ method.
#define TRACE
#include <xtd/diagnostics/trace>
#include <xtd/console>
using namespace xtd;
using namespace xtd::diagnostics;
auto main() -> int {
// Uncomment following lines to remove assert dialog
//for (auto listener : trace::listeners())
// if (is<default_trace_listener>(listener))
// as<default_trace_listener>(listener)->assert_ui_enabled(false);
auto index = 0;
console::write_line("Start application");
trace::cassert_(index > 0, "index must be greater than 0");
console::write_line("End application");
}
// This code produces the following output :
//
// > If user clicks assert dialog 'Abort' button:
// Start application
//
// > If user clicks assert dialog 'Retry' button:
// Start application
// > Break the debugger on file tace_cassert.cpp line 13.
// > If user choose continue running after break.
// End application
//
// > If user clicks assert dialog 'Ignore' button:
// Start application
// End application