xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
stack_trace.h
Go to the documentation of this file.
1 #pragma once
5 #include <exception>
6 #include <memory>
7 #include <vector>
8 #include "../core_export.h"
9 #include "../object.h"
10 #include "../ustring.h"
11 #include "stack_frame.h"
12 
14 namespace xtd {
16  class system_exception;
18 
20  namespace diagnostics {
32  class core_export_ stack_trace : public object {
33  public:
35  using stack_frame_collection = std::vector<xtd::diagnostics::stack_frame>;
36 
73  stack_trace();
110  explicit stack_trace(bool need_file_info);
121  explicit stack_trace(const xtd::diagnostics::stack_frame& frame);
126  stack_trace(const std::exception& exception);
131  explicit stack_trace(size_t skip_frames);
138  stack_trace(const std::exception& exception, size_t skip_frames);
176  stack_trace(size_t skip_frames, bool need_file_info);
183  stack_trace(const std::exception& exception, size_t skip_frames, bool need_file_info);
188  stack_trace(const std::exception& exception, bool need_file_info);
190  stack_trace(const stack_trace&) = default;
191  stack_trace& operator=(const stack_trace&) = default;
193 
229  size_t frame_count() const;
230 
268  const xtd::diagnostics::stack_frame& get_frame(size_t index);
269 
285  const stack_frame_collection& get_frames() const;
286 
296  xtd::ustring to_string() const noexcept;
297 
299  friend std::ostream& operator<<(std::ostream& os, const xtd::diagnostics::stack_trace& stack_trace) noexcept {return os << stack_trace.to_string();}
301 
304  static constexpr size_t METHODS_TO_SKIP = 0;
305 
306  private:
307  friend class xtd::system_exception;
308  stack_trace(const xtd::ustring& str, size_t skip_frames, bool need_file_info);
310 
311  stack_frame_collection frames_;
312  };
313  }
314 }
Defines the base class for predefined exceptions in the xtd namespace.
Definition: system_exception.h:24
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents a stack trace, which is an ordered collection of one or more stack frames.
Definition: stack_trace.h:32
virtual xtd::ustring stack_trace() const noexcept
Gets a string representation of the immediate frames on the call stack.
Definition: system_exception.h:126
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
xtd::ustring to_string() const noexcept
Builds a readable representation of the stack trace.
std::vector< xtd::diagnostics::stack_frame > stack_frame_collection
Represents a stack_frame collection.
Definition: stack_trace.h:35
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:29
static stack_frame empty() noexcept
Return an empty stack frame.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
Contains xtd::diagnostics::stack_frame class.
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37