#include <xtd/xtd>
class stack_trace_sample {
public:
void my_public_method() {
my_protected_method();
}
protected:
void my_protected_method() {
auto mic = my_internal_class {};
mic.throws_exception();
}
private:
class my_internal_class {
public:
void throws_exception() {
try {
throw system_exception("A problem was encountered.");
} catch (const system_exception&) {
auto st = diagnostics::stack_trace {true};
string stack_indent = "";
for (auto i = 0ul; i < st.frame_count(); i++) {
auto sf = st.get_frame(i);
console::write_line();
console::write_line(stack_indent + " Method: {0}", sf.get_method());
console::write_line(stack_indent + " File: {0}", sf.get_file_name());
console::write_line(stack_indent + " Line Number: {0}", sf.get_file_line_number());
stack_indent += " ";
}
throw;
}
}
};
};
auto main() -> int {
auto sample = stack_trace_sample {};
try {
sample.my_public_method();
} catch (const system_exception&) {
auto st = diagnostics::stack_trace {true};
for (
auto i = 0ul;
i < st.frame_count();
i++) {
auto sf = st.get_frame(i);
console::write_line();
console::write_line("High up the call stack, Method: {0}", sf.get_method());
console::write_line("High up the call stack, Line Number: {0}", sf.get_file_line_number());
}
}
}
@ i
The I key.
Definition console_key.hpp:104