diff --git a/src/xtd.core/include/xtd/exception.h b/src/xtd.core/include/xtd/exception.h index 2e9c21ae502..132776f84fd 100644 --- a/src/xtd.core/include/xtd/exception.h +++ b/src/xtd.core/include/xtd/exception.h @@ -105,11 +105,24 @@ namespace xtd { /// @brief Gets a link to the help file associated with this exception. /// @return A string represent a link to Help file associated with exception virtual const xtd::string& help_link() const noexcept; + /// @brief Sets a link to the help file associated with this exception. + /// @param value A string represent a link to Help file associated with exception + virtual void help_link(const xtd::string& value) noexcept; + + /// @brief Gets HRESULT, a coded numerical value that is assigned to a specific exception. + /// @return The HRESULT value. + virtual int32 h_result() const noexcept; + /// @brief Sets HRESULT, a coded numerical value that is assigned to a specific exception. + /// @param value The HRESULT value. + virtual void h_result(int32 value) noexcept; /// @brief Gets error associate to the exception /// @return An error_code represent a Error associate to the exception - virtual std::error_code error_code() const noexcept; - + virtual const std::error_code& error_code() const noexcept; + /// @brief Sets error associate to the exception + /// @param value An error_code represent a Error associate to the exception + virtual void error_code(const std::error_code& value) noexcept; + /// @brief Gets the exception instance that caused the current exception. /// @return An instance of exception that describes the error that caused the current exception. The inner_exception property returns the same value as was passed into the constructor, or a null reference if the inner exception value was not supplied to the constructor. virtual exception_ref inner_exception() const noexcept; @@ -130,6 +143,15 @@ namespace xtd { /// @return A string represent a full class name of the exception virtual const xtd::string& name() const noexcept; + /// @brief Gets the name of the application or the object that causes the error. + /// @return The name of the application or the object that causes the error. + /// @remarks If the xtd::exception::source property is not set explicitly, the runtime automatically sets it to the name of the assembly in which the exception originated. + virtual const xtd::string& source() const noexcept; + /// @brief Sets the name of the application or the object that causes the error. + /// @return The name of the application or the object that causes the error. + /// @remarks If the xtd::exception::source property is not set explicitly, the runtime automatically sets it to the name of the assembly in which the exception originated. + virtual void source(const xtd::string& value) noexcept; + /// @brief Gets a string representation of the immediate frames on the call stack. /// @return A string that describes the immediate frames of the call stack. virtual xtd::string stack_trace() const noexcept; diff --git a/src/xtd.core/src/xtd/exception.cpp b/src/xtd.core/src/xtd/exception.cpp index b4d357cb8bf..20f7572fc89 100644 --- a/src/xtd.core/src/xtd/exception.cpp +++ b/src/xtd.core/src/xtd/exception.cpp @@ -3,6 +3,8 @@ #include "../../include/xtd/environment.h" #include "../../include/xtd/exception.h" #include "../../include/xtd/diagnostics/stack_trace.h" +#include "../../include/xtd/io/path.h" +#include "../../include/xtd/reflection/assembly.h" using namespace xtd; @@ -15,6 +17,8 @@ struct exception::data { exception_ref inner_exception; std::error_code error; xtd::string help_link; + int32 h_result = 0; + xtd::string source = io::path::get_file_name(reflection::assembly::get_executing_assembly().location()); xtd::diagnostics::stack_frame information; xtd::sptr stack_trace; }; @@ -63,6 +67,19 @@ const xtd::string& exception::help_link() const noexcept { return data_->help_link; } +void exception::help_link(const xtd::string& value) noexcept { + if (data_->help_link == value) return; + data_->help_link = value; +} + +int32 exception::h_result() const noexcept { + return data_->h_result; +} + +void exception::h_result(int32 value) noexcept { + data_->h_result = value; +} + bool exception::enable_stack_trace() noexcept { return enable_stack_trace_; } @@ -71,10 +88,15 @@ void exception::enable_stack_trace(bool enable) noexcept { enable_stack_trace_ = enable; } -std::error_code exception::error_code() const noexcept { +const std::error_code& exception::error_code() const noexcept { return data_->error; } +void exception::error_code(const std::error_code& value) noexcept { + if (data_->error == value) return; + data_->error = value; +} + exception::exception_ref exception::inner_exception() const noexcept { return data_->inner_exception; } @@ -98,6 +120,15 @@ const xtd::string& exception::name() const noexcept { return (data_->name = get_type().full_name()); } +const xtd::string& exception::source() const noexcept { + return data_->source; +} + +void exception::source(const xtd::string& value) noexcept { + if (data_->source == value) return; + data_->source = value; +} + xtd::string exception::stack_trace() const noexcept { return stack_trace_to_string(); }