xtd 1.0.0
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "core_export.hpp"
7#include "h_result.hpp"
8#include "object.hpp"
9#include "nullopt.hpp"
10#include "optional.hpp"
11#include "ptr.hpp"
12#include "uptr.hpp"
13#include "string.hpp"
14#include <exception>
15#include <system_error>
16
18struct __xtd_exception_gui__;
19auto __xtd_load_exception_gui__() -> void;
21
23namespace xtd {
25 class system_exception;
27
34 class core_export_ exception : public object, public std::exception {
35 public:
37
42
44
58 template<typename exception_t>
61
63 exception(exception&&) = default;
64 exception(const exception&) = default;
65 exception& operator =(exception&&) = default;
66 exception& operator =(const exception&) = default;
68
70
74 [[nodiscard]] virtual auto help_link() const noexcept -> const xtd::string&;
77 virtual auto help_link(const xtd::string& value) noexcept -> void;
78
81 [[nodiscard]] virtual auto h_result() const noexcept -> xtd::int32;
84 virtual auto h_result(xtd::int32 value) noexcept -> void;
85
88 [[nodiscard]] virtual auto error_code() const noexcept -> const std::error_code&;
91 virtual auto error_code(const std::error_code& value) noexcept -> void;
92
95 [[nodiscard]] virtual auto inner_exception() const noexcept -> exception_ref;
96
99 [[nodiscard]] virtual auto message() const noexcept -> const xtd::string&;
100
104 [[nodiscard]] virtual auto source() const noexcept -> const xtd::string&;
108 virtual auto source(const xtd::string& value) noexcept -> void;
109
112 [[nodiscard]] virtual auto stack_trace() const noexcept -> xtd::string;
114
116
120 [[nodiscard]] virtual auto get_last_stack_frame() const noexcept -> const xtd::diagnostics::stack_frame&;
123 [[nodiscard]] auto to_string() const noexcept -> xtd::string override;
124
127 [[nodiscard]] auto what() const noexcept -> const char* override;
129
131
135 [[nodiscard]] static auto enable_stack_trace() noexcept -> bool;
138 static auto enable_stack_trace(bool enable) noexcept -> void;
139
143 static auto show_exception(const std::exception& e) -> xtd::int32 {
144 load_exception_gui();
145 return show_exception_(e);
146 }
147
149 static auto show_exception() -> xtd::int32 {
150 load_exception_gui();
151 return show_exception_();
152 }
153
154
155 private:
156 friend struct ::__xtd_exception_gui__;
157 exception(const xtd::optional<xtd::string>& message, xtd::uptr<xtd::exception>&& inner_exception, const xtd::diagnostics::stack_frame& stack_frame, bool);
158 [[nodiscard]] auto stack_trace_to_string() const noexcept -> xtd::string;
159
160 [[nodiscard]] auto get_name() const noexcept -> const xtd::string&;
161 static auto load_exception_gui() -> void {
162#if __XTD_CURRENT_TARGET_ID__ == __XTD_TARGET_ID_GUI_APPLICATION__ || __XTD_CURRENT_TARGET_ID__ == __XTD_TARGET_ID_UNKNOWN__
163 __xtd_load_exception_gui__();
164#endif
165 }
166 static auto show_exception_(const std::exception& e) -> xtd::int32;
167 static auto show_exception_() -> xtd::int32;
168
169 struct data;
170 xtd::ptr<data> data_;
171 static bool enable_stack_trace_;
172 static xtd::intptr show_exception_gui_with_exception;
173 static xtd::intptr show_exception_gui;
174 };
175}
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:46
static auto current(const xtd::diagnostics::source_location &value=xtd::diagnostics::source_location::current()) noexcept -> xtd::diagnostics::stack_frame
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.hpp:34
virtual auto get_last_stack_frame() const noexcept -> const xtd::diagnostics::stack_frame &
Gets the last stack frame where the exception occurred.
virtual auto source() const noexcept -> const xtd::string &
Gets the name of the application or the object that causes the error.
static auto show_exception() -> xtd::int32
Shows unspecified exception with xtd::forms::exception_dialog or xtd::console.
Definition exception.hpp:149
auto to_string() const noexcept -> xtd::string override
Returns a string that represents the current exception.
static auto enable_stack_trace() noexcept -> bool
Gets if the generation of the stack trace is enabled.
static auto show_exception(const std::exception &e) -> xtd::int32
Shows speciefied exception with xtd::forms::exception_dialog or xtd::console.
Definition exception.hpp:143
exception(const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class exception.
virtual auto stack_trace() const noexcept -> xtd::string
Gets a string representation of the immediate frames on the call stack.
virtual auto inner_exception() const noexcept -> exception_ref
Gets the exception instance that caused the current exception.
auto what() const noexcept -> const char *override
Gets message associate to the exception.
exception(const xtd::optional< xtd::string > &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class exception.
virtual auto help_link() const noexcept -> const xtd::string &
Gets a link to the help file associated with this exception.
virtual auto message() const noexcept -> const xtd::string &
Gets message associate to the exception.
virtual auto error_code() const noexcept -> const std::error_code &
Gets error associate to the exception.
virtual auto h_result() const noexcept -> xtd::int32
Gets HRESULT, a coded numerical value that is assigned to a specific exception.
exception(const xtd::optional< xtd::string > &message, const exception_t &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class exception.
Definition exception.hpp:59
xtd::optional< xtd::ref< const xtd::exception > > exception_ref
Optional reference wrapper on std::exception.
Definition exception.hpp:40
auto memberwise_clone() const -> xtd::unique_ptr_object< object_t >
Creates a shallow copy of the current object.
object()=default
Create a new instance of the ultimate base class object.
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
Contains core_export_ keyword.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
xtd::unique_ptr_object< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::optional< type_t > optional
Represents the optional alias on std::optional.
Definition optional.hpp:26
@ e
The E key.
Definition console_key.hpp:96
Contains xtd::h_result class.
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::nullopt valiue.
Contains xtd::object class.
Contains xtd::optional type.
Contains xtd::ptr type.
Contains xtd::diagnostics::stack_frame class.
Contains xtd::string alias.
Contains xtd::uptr type.