Demonstrates how to create a simple xtd::diagnostics::stack_trace class and iterate through its frames to obtain debugging and diagnostic information.
#include <xtd/diagnostics/stack_trace>
#include <xtd/console>
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 {
for (
auto i = 0ul;
i < st.frame_count();
i++) {
auto sf = st.get_frame(
i);
stack_indent += " ";
}
throw;
}
}
};
};
auto main()->int {
auto sample = stack_trace_sample {};
try {
sample.my_public_method();
for (
auto i = 0ul;
i < st.frame_count();
i++) {
}
}
}