#include <xtd/xtd>
void method2(int count) {
try {
if (count < 5)
throw argument_exception("count too large", "count");
} catch (const system_exception&) {
auto st = diagnostics::stack_trace {};
auto st1 = diagnostics::stack_trace {diagnostics::stack_frame {2, true}};
console::write_line(" Stack trace for Method2: {0}", st1.to_string());
console::write_line(st.to_string());
throw;
}
}
void method1() {
try {
method2(4);
} catch (const system_exception&) {
auto st = diagnostics::stack_trace {};
auto st1 = diagnostics::stack_trace {diagnostics::stack_frame {true}};
console::write_line(" Stack trace for Method1: {0}", st1.to_string());
console::write_line(st.to_string());
auto st2 = diagnostics::stack_trace {diagnostics::stack_frame {1, true}};
console::write_line(" Stack trace for next level frame: {0}", st2.to_string());
throw;
}
}
auto main() -> int {
try {
method1();
} catch (const system_exception&) {
auto st = diagnostics::stack_trace {};
auto st1 = diagnostics::stack_trace {diagnostics::stack_frame {true}};
console::write_line(" Stack trace for Main: {0}", st1.to_string());
console::write_line(st.to_string());
}
console::write_line("Press Enter to exit.");
console::read_key();
}