#include <stack_trace.h>
Represents a stack trace, which is an ordered collection of one or more stack frames.
- Inheritance
- xtd::object → xtd::diagnostics::stack_trace
- Namespace
- xtd::diagnostics
- Library
- xtd.core
- Examples
- The following console application demonstrates how to create a simple xtd::diagnostics::stack_trace and iterate through its frames to obtain debugging and diagnostic information.
#include <xtd/xtd>
class stack_trace_sample {
public:
void my_public_method() {
my_protected_method();
}
protected:
void my_protected_method() {
my_internal_class mic;
mic.throws_exception();
}
private:
class my_internal_class {
public:
void throws_exception() {
try {
stack_indent += " ";
}
throw;
}
}
};
};
auto main()->int {
stack_trace_sample sample;
try {
sample.my_public_method();
}
}
}
- Examples:
- stack_frame.cpp, stack_trace.cpp, and stack_trace_simple.cpp.
|
| stack_trace () |
| Initializes a new instance of the xtd::diagnostics::stack_trace class from the caller's frame. More...
|
|
| stack_trace (bool need_file_info) |
| Initializes a new instance of the xtd::diagnostics::stack_trace class from the caller's frame, optionally capturing source information. More...
|
|
| stack_trace (const xtd::diagnostics::stack_frame &frame) |
| Initializes a new instance of the xtd::diagnostics::stack_trace class that contains a single frame. More...
|
|
| stack_trace (const std::exception &exception) |
| Initializes a new instance of the xtd::diagnostics::stack_trace class using the provided exception object. More...
|
|
| stack_trace (size_t skip_frames) |
| Initializes a new instance of the xtd::diagnostics::stack_trace class from the caller's frame, skipping the specified number of frames. More...
|
|
| stack_trace (const std::exception &exception, size_t skip_frames) |
| Initializes a new instance of the StackTrace class using the provided exception object and skipping the specified number of frames. More...
|
|
| 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. More...
|
|
| stack_trace (const std::exception &exception, size_t skip_frames, bool need_file_info) |
| Initializes a new instance of the xtd::diagnostics::stack_trace class using the provided exception object, skipping the specified number of frames and optionally capturing source information. More...
|
|
| stack_trace (const std::exception &exception, bool need_file_info) |
| Initializes a new instance of the xtd::diagnostics::stack_trace class, using the provided exception object and optionally capturing source information. More...
|
|
|
static constexpr size_t | METHODS_TO_SKIP = 0 |
| Defines the default for the number of methods to omit from the stack trace. This field is constant. More...
|
|
|
size_t | frame_count () const noexcept |
| Gets the number of frames in the stack trace. More...
|
|
|
| object ()=default |
| Create a new instance of the ultimate base class object. More...
|
|
bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object. More...
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type. More...
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| Gets the type of the current instance. More...
|
|
static bool | equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are considered equal. More...
|
|
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are the same instance. More...
|
|
◆ stack_frame_collection
◆ stack_trace() [1/9]
xtd::diagnostics::stack_trace::stack_trace |
( |
| ) |
|
Initializes a new instance of the xtd::diagnostics::stack_trace class from the caller's 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) {
if (st.frame_count() >1) {
sf = st.get_frame(st.frame_count() - 1);
}
throw;
}
}
◆ 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_info | true 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) {
stack_frame sf = st.get_frame(0);
if (st.frame_count() >1) {
sf = st.get_frame(st.frame_count() - 1);
}
throw;
}
}
◆ stack_trace() [3/9]
Initializes a new instance of the xtd::diagnostics::stack_trace class that contains a single frame.
- Parameters
-
- Examples
- The following code example writes stack trace information to an event log entry.
◆ stack_trace() [4/9]
xtd::diagnostics::stack_trace::stack_trace |
( |
const std::exception & |
exception | ) |
|
|
explicit |
Initializes a new instance of the xtd::diagnostics::stack_trace class using the provided exception object.
- Parameters
-
exception | The exception object from which to construct the stack trace. |
◆ stack_trace() [5/9]
xtd::diagnostics::stack_trace::stack_trace |
( |
size_t |
skip_frames | ) |
|
|
explicit |
Initializes a new instance of the xtd::diagnostics::stack_trace class from the caller's frame, skipping the specified number of frames.
- Parameters
-
skip_frames | The number of frames up the stack from which to start the trace. |
◆ stack_trace() [6/9]
xtd::diagnostics::stack_trace::stack_trace |
( |
const std::exception & |
exception, |
|
|
size_t |
skip_frames |
|
) |
| |
Initializes a new instance of the StackTrace class using the provided exception object and skipping the specified number of frames.
- Parameters
-
exception | The exception object from which to construct the stack trace. |
skip_framed | The number of frames up the stack from which to start the trace. |
◆ 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_frames | The number of frames up the stack from which to start the trace. |
need_file_info | true 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) {
stack_frame sf = st.get_frame(0);
if (st.frame_count() >1) {
sf = st.get_frame(st.frame_count() - 1);
}
throw;
}
}
◆ stack_trace() [8/9]
xtd::diagnostics::stack_trace::stack_trace |
( |
const std::exception & |
exception, |
|
|
size_t |
skip_frames, |
|
|
bool |
need_file_info |
|
) |
| |
Initializes a new instance of the xtd::diagnostics::stack_trace class using the provided exception object, skipping the specified number of frames and optionally capturing source information.
- Parameters
-
exception | The exception object from which to construct the stack trace. |
skip_frames | The number of frames up the stack from which to start the trace. |
need_file_info | true to capture the file name, line number, and column number; otherwise, false. |
◆ stack_trace() [9/9]
xtd::diagnostics::stack_trace::stack_trace |
( |
const std::exception & |
exception, |
|
|
bool |
need_file_info |
|
) |
| |
Initializes a new instance of the xtd::diagnostics::stack_trace class, using the provided exception object and optionally capturing source information.
- Parameters
-
exception | The exception object from which to construct the stack trace. |
need_file_info | true to capture the file name, line number, and column number; otherwise, false. |
◆ frame_count()
size_t xtd::diagnostics::stack_trace::frame_count |
( |
| ) |
const |
|
noexcept |
Gets the number of frames in the stack trace.
- Returns
- The number of frames in the stack trace.
- 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) {
stack_frame sf = st.get_frame(0);
if (st.frame_count() >1) {
sf = st.get_frame(st.frame_count() - 1);
}
throw;
}
}
- Examples:
- stack_trace_simple.cpp.
◆ get_frame()
Gets the specified stack frame.
- Parameters
-
index | The 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) {
stack_frame sf = st.get_frame(0);
if (st.frame_count() >1) {
sf = st.get_frame(st.frame_count() - 1);
}
throw;
}
}
- Examples:
- stack_trace_simple.cpp.
◆ get_frames()
Returns a copy of all stack frames in the current stack trace.
- Returns
- An array of type xtd::diagnostics::stack_frame representing the function calls in the stack trace.
- Examples
- The following code example demonstrates enumerating the frames in a xtd::diagnostics::stack_trace.
for(const stack_frame& sf : st_frames) {
}
◆ to_string()
xtd::ustring xtd::diagnostics::stack_trace::to_string |
( |
| ) |
const |
|
overridevirtualnoexcept |
Builds a readable representation of the stack trace.
- Returns
- A readable representation of the stack trace.
- Examples
- The following code example writes stack trace information to an event log entry.
Reimplemented from xtd::object.
- Examples:
- stack_frame.cpp.
◆ METHODS_TO_SKIP
constexpr size_t xtd::diagnostics::stack_trace::METHODS_TO_SKIP = 0 |
|
static |
Defines the default for the number of methods to omit from the stack trace. This field is constant.
The documentation for this class was generated from the following file: