xtd 0.2.0
Loading...
Searching...
No Matches
xtd::startup Class Referencefinal
Inheritance diagram for xtd::startup:
xtd::static_object

Definition

Defines the xtd::startup object that can be used in the main method to safely call the application's main entry point.

Namespace
xtd
Library
xtd.core

Public Static Methods

template<typename main_function_t >
static int safe_run (main_function_t main_function)
 Safely call the specified application's main entry point.
 
template<typename main_function_t >
static int safe_run (main_function_t main_function, int argc, char *argv[])
 Safely call the specified application's main entry point, argc and argv.
 

Member Function Documentation

◆ safe_run() [1/2]

template<typename main_function_t >
static int xtd::startup::safe_run ( main_function_t  main_function)
inlinestatic

Safely call the specified application's main entry point.

Parameters
main_functionThe main method to safety call.
Remarks
The main_function is called in try and catch. If an exception occurs, a generic message is displayed.
The xtd::threading::thread::join_all method are cal before exit. See xtd::threading::thread::join_all for more information.
The xtd::startup::run method is used by the keyword startup_.
Parameters
main_classThe class that contains the static main method.
Examples
This example show a main_function without arguments and without return code
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
using namespace xtd;
namespace startup1_example {
class program {
public:
static void main() {
// Write arguments to the console output
for (auto arg : environment::get_command_line_args())
console::write_line(arg);
// return 42
environment::exit_code(42);
}
};
}
auto main() -> int {
return startup::safe_run(startup1_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// startup1_example::program::main();
// return xtd::environment::exit_code();
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// /!---OMITTED---!/startup1
// one
// two
// three four
// five
Represents the standard input, output, and error streams for console applications.
Definition console.hpp:36
The environment class.
Definition environment.hpp:67
static int safe_run(main_function_t main_function)
Safely call the specified application's main entry point.
Definition startup.hpp:47
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
This example show a main_function with a return code and without arguments
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
using namespace xtd;
namespace startup2_example {
class program {
public:
static int main() {
// Write arguments to the console output
for (auto arg : environment::get_command_line_args())
console::write_line(arg);
return 42;
}
};
}
auto main() -> int {
return startup::safe_run(startup2_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// return startup2_example::program::main();
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// /!---OMITTED---!/startup2
// one
// two
// three four
// five
This example show a main_function with argument and without return code
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
using namespace xtd;
namespace startup3_example {
class program {
public:
static void main(const argument_collection& args) {
// Write arguments to the console output
for (auto arg : args)
console::write_line(arg);
// return 42
environment::exit_code(42);
}
};
}
auto main() -> int {
return startup::safe_run(startup3_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// auto args = xtd::environment::get_command_line_args();
// startup3_example::program::main({args.begin() + 1, args.end()});
// return xtd::environment::exit_code();
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// one
// two
// three four
// five
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
This example show a main_function with argument and return code
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
namespace startup4_example {
class program {
public:
static int main(const argument_collection& args) {
// Write arguments to the console output
for (auto arg : args)
console::write_line(arg);
return 42;
}
};
}
auto main() -> int {
return startup::safe_run(startup4_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// auto args = xtd::environment::get_command_line_args();
// return startup34example::program::main({args.begin() + 1, args.end()});
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// one
// two
// three four
// five
Examples
startup.cpp.

◆ safe_run() [2/2]

template<typename main_function_t >
static int xtd::startup::safe_run ( main_function_t  main_function,
int  argc,
char *  argv[] 
)
inlinestatic

Safely call the specified application's main entry point, argc and argv.

Parameters
main_functionThe main method to safety call.
argcthe main argc param.
argvthe main argv param.
Remarks
The main_function is called in try and catch. If an exception occurs, a generic message is displayed.
The xtd::threading::thread::join_all method are cal before exit. See xtd::threading::thread::join_all for more information.
The xtd::startup::run method is used by the keyword startup_.
Parameters
main_classThe class that contains the static main method.
Examples
This example show a main_function without arguments and without return code
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
using namespace xtd;
namespace startup1_example {
class program {
public:
static void main() {
// Write arguments to the console output
for (auto arg : environment::get_command_line_args())
console::write_line(arg);
// return 42
environment::exit_code(42);
}
};
}
auto main() -> int {
return startup::safe_run(startup1_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// startup1_example::program::main();
// return xtd::environment::exit_code();
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// /!---OMITTED---!/startup1
// one
// two
// three four
// five
This example show a main_function with a return code and without arguments
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
using namespace xtd;
namespace startup2_example {
class program {
public:
static int main() {
// Write arguments to the console output
for (auto arg : environment::get_command_line_args())
console::write_line(arg);
return 42;
}
};
}
auto main() -> int {
return startup::safe_run(startup2_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// return startup2_example::program::main();
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// /!---OMITTED---!/startup2
// one
// two
// three four
// five
This example show a main_function with argument and without return code
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
using namespace xtd;
namespace startup3_example {
class program {
public:
static void main(const argument_collection& args) {
// Write arguments to the console output
for (auto arg : args)
console::write_line(arg);
// return 42
environment::exit_code(42);
}
};
}
auto main() -> int {
return startup::safe_run(startup3_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// auto args = xtd::environment::get_command_line_args();
// startup3_example::program::main({args.begin() + 1, args.end()});
// return xtd::environment::exit_code();
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// one
// two
// three four
// five
This example show a main_function with argument and return code
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
namespace startup4_example {
class program {
public:
static int main(const argument_collection& args) {
// Write arguments to the console output
for (auto arg : args)
console::write_line(arg);
return 42;
}
};
}
auto main() -> int {
return startup::safe_run(startup4_example::program::main);
}
// Is approximately the same as :
//
// auto main() -> int {
// try {
// auto args = xtd::environment::get_command_line_args();
// return startup34example::program::main({args.begin() + 1, args.end()});
// } catch(const std::exception& e) {
// if (dynamic_cast<const xtd::system_exception*>(&e)) xtd::console::write_line(static_cast<const xtd::system_exception&>(e).to_string());
// else xtd::console::write_line(e.what());
// } catch(...) {
// xtd::console::write_line("Unhandled exception: Unknown exception occurred");
// }
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// one
// two
// three four
// five

The documentation for this class was generated from the following file: