xtd 0.2.0
Loading...
Searching...
No Matches

◆ stack_trace() [7/9]

xtd::diagnostics::stack_trace::stack_trace ( size_t  skip_frames,
bool  need_file_info 
)

Initializes a new instance of the xtd::diagnostics::stack_trace class from the caller's frame, skipping the specified number of frames and optionally capturing source information.

Parameters
skip_framesThe number of frames up the stack from which to start the trace.
need_file_infotrue to capture the file name, line number, and column number; otherwise, false.
Examples
The following code example displays the first and last function calls in a stack trace.
void Level_5_method() {
try {
class_level_6 nested_class;
nested_class.level_6_method();
} catch (const exception& e) {
console::write_line(" Level_5_method exception handler");
// Display the most recent function call.
stack_frame sf = st.get_frame(0);
console::write_line(" Exception in method: ");
if (st.frame_count() >1) {
// Display the highest-level function call
// in the trace.
sf = st.get_frame(st.frame_count() - 1);
console::write_line(" Original function call at top of call stack):");
}
console::write_line(" ... throwing exception to next level ...");
console::write_line("-------------------------------------------------\n");
throw;
}
}
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
virtual const xtd::string & get_method() const noexcept
Gets the method in which the frame is executing.
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.h:46
size_t frame_count() const noexcept
Gets the number of frames in the stack trace.
const xtd::diagnostics::stack_frame & get_frame(size_t index) noexcept
Gets the specified stack frame.
Represents a stack trace, which is an ordered collection of one or more stack frames.
Definition stack_trace.h:40
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.h:26
@ e
The E key.
Remarks
If the number of frames to skip is greater than or equal to the total number of frames on the call stack at the time the instance is created, the xtd::diagnostics::stack_trace will contain no frames.