Shows how to use argument_exception exception.
#include <xtd/xtd>
int divide_by_two(int num) {
if ((num & 1) == 1) throw argument_exception("Number must be even");
return num / 2;
}
auto main() -> int {
console::write_line("10 divided by 2 is {0}", divide_by_two(10));
try {
console::write_line("7 divided by 2 is {0}", divide_by_two(7));
} catch (const argument_exception&) {
console::write_line("7 is not divided by 2 integrally.");
}
}