following code example demonstrate the use of following code example demonstrate how to manage exception with xtd::forms::application class.
#include <xtd/xtd>
using namespace std;
class main_form : public form {
public:
static void main() {
application::run(main_form());
}
main_form() {
text("application and exception example");
generate_handled_exception_button.auto_size(true);
generate_handled_exception_button.location({10, 10});
generate_handled_exception_button.parent(*this);
generate_handled_exception_button.text("Generate handled exception");
generate_handled_exception_button.click +=
event_handler(*
this, &main_form::generate_handled_exception);
generate_exception_button.auto_size(true);
generate_exception_button.location({10, 40});
generate_exception_button.parent(*this);
generate_exception_button.text("Generate exception");
generate_exception_button.click +=
event_handler(*
this, &main_form::generate_exception);
generate_system_exception_button.auto_size(true);
generate_system_exception_button.location({10, 70});
generate_system_exception_button.parent(*this);
generate_system_exception_button.text("Generate system exception");
generate_system_exception_button.click +=
event_handler(*
this, &main_form::generate_system_exception);
generate_unknown_exception_button.auto_size(true);
generate_unknown_exception_button.location({10, 100});
generate_unknown_exception_button.parent(*this);
generate_unknown_exception_button.text("Generate unknown exception");
generate_unknown_exception_button.click +=
event_handler(*
this, &main_form::generate_unknown_exception);
}
private:
void generate_handled_exception() {
try {
message_box::show(*
this,
e.message(), ustring::format(
"Exception {} handled",
e.name()));
}
}
void generate_unknown_exception() {throw "Unknown exception occured";}
button generate_handled_exception_button;
button generate_exception_button;
button generate_system_exception_button;
button generate_unknown_exception_button;
};
Defines the base class for predefined exceptions in the xtd namespace.
Definition: system_exception.h:24
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition: event_handler.h:33
#define startup_(main_class)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition: startup.h:49
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
@ invalid_argument
Invalid argument.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17