#include <xtd/xtd>
auto 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::from_stack_frame(diagnostics::stack_frame {2, true});
console::write(" Stack trace for Method2: {0}", st1.to_string());
console::write(st.to_string());
throw;
}
}
auto method1() {
try {
method2(4);
} catch (const system_exception&) {
auto st = diagnostics::stack_trace {};
auto st1 = diagnostics::stack_trace::from_stack_frame(diagnostics::stack_frame {true});
console::write(" Stack trace for Method1: {0}", st1.to_string());
console::write(st.to_string());
auto st2 = diagnostics::stack_trace::from_stack_frame(diagnostics::stack_frame {1, true});
console::write(" 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::from_stack_frame(diagnostics::stack_frame {true});
console::write(" Stack trace for Main: {0}", st1.to_string());
console::write(st.to_string());
}
console::write_line("Press Enter to exit.");
console::read_key();
}