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

◆ get_frame()

const xtd::diagnostics::stack_frame & xtd::diagnostics::stack_trace::get_frame ( size_t  index)
noexcept

Gets the specified stack frame.

Parameters
indexThe index of the stack frame requested.
Returns
The specified stack frame.
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 system_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:40
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 system_exception.h:24
@ e
The E key.
Remarks
Stack frames are numbered starting at 0, which is the last stack frame pushed.
Examples
stack_trace_simple.cpp.