Skip to content

Commit

Permalink
Add properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Sep 26, 2024
1 parent 7f79a9e commit 39ed507
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/xtd.core/include/xtd/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
33 changes: 32 additions & 1 deletion src/xtd.core/src/xtd/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<xtd::diagnostics::stack_trace> stack_trace;
};
Expand Down Expand Up @@ -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_;
}
Expand All @@ -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;
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 39ed507

Please sign in to comment.