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

◆ stack_trace() [2/9]

xtd::diagnostics::stack_trace::stack_trace ( bool  need_file_info)
explicit

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

Parameters
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 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
The xtd::diagnostics::stack_trace is created with the caller's current thread.