From 5d5ce5d02780230032df6fce9149548bab9a5231 Mon Sep 17 00:00:00 2001 From: Gammasoft Date: Tue, 24 Sep 2024 21:48:08 +0200 Subject: [PATCH] Add throw_if_zero method --- .../xtd/argument_out_of_range_exception.h | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/xtd.core/include/xtd/argument_out_of_range_exception.h b/src/xtd.core/include/xtd/argument_out_of_range_exception.h index d5f547701f1..7cb4351079b 100644 --- a/src/xtd.core/include/xtd/argument_out_of_range_exception.h +++ b/src/xtd.core/include/xtd/argument_out_of_range_exception.h @@ -17,59 +17,59 @@ namespace xtd { /// xtd.core /// @ingroup xtd_core exceptions /// @par Examples - /// The following example demonstrates how to throw and catch an argument_out_of_range_exception. + /// The following example demonstrates how to throw and catch an xtd::argument_out_of_range_exception. /// @include argument_out_of_range_exception.cpp class argument_out_of_range_exception : public argument_exception { public: /// @name Public Constructors /// @{ - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. /// @remarks Message is set with the default message associate to the exception. explicit argument_out_of_range_exception(const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(default_message(), info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. explicit argument_out_of_range_exception(const xtd::string& message, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(message, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param error Error code associate to the exception. /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. explicit argument_out_of_range_exception(const xtd::string& message, const std::error_code& error, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(message, error, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param help_link Help link string associate to the exception. /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. explicit argument_out_of_range_exception(const xtd::string& message, const xtd::string& help_link, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(message, help_link, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param error Error code associate to the exception. /// @param help_link Help link string associate to the exception. explicit argument_out_of_range_exception(const xtd::string& message, const std::error_code& error, const xtd::string& help_link, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(message, error, help_link, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param inner_exception The exception that is the cause of the current exception. /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. /// @remarks Message is set with the default message associate to the exception. explicit argument_out_of_range_exception(const std::exception& inner_exception, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(default_message(), inner_exception, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. explicit argument_out_of_range_exception(const xtd::string& message, const std::exception& inner_exception, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(message, inner_exception, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param error Error code associate to the exception. /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. explicit argument_out_of_range_exception(const xtd::string& message, const std::exception& inner_exception, const std::error_code& error, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(message, inner_exception, error, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param help_link Help link string associate to the exception. /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. explicit argument_out_of_range_exception(const xtd::string& message, const std::exception& inner_exception, const xtd::string& help_link, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) : argument_exception(message, inner_exception, help_link, info) {} - /// @brief Create a new instance of class argument_out_of_range_exception + /// @brief Create a new instance of class xtd::argument_out_of_range_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param error Error code associate to the exception. @@ -83,6 +83,18 @@ namespace xtd { argument_out_of_range_exception& operator =(const argument_out_of_range_exception&) = default; /// @endcond + /// @name Public static Methods + + /// @{ + /// @brief Throws an xtd::argument_out_of_range_exception if value is zero. + /// @tparam value_t The type of the object to validate. + /// @param value The argument to validate as non-zero. + /// @param param_name (optional) The name of the parameter with which `value` corresponds. + /// @param information (optional) Contains current information about member name, file path and line number in the file where the exception is occurred. Typically #current_stack_frame_. + template + static void throw_if_zero(const value_t& value, const xtd::string& param_name = xtd::string::empty_string, const xtd::diagnostics::stack_frame& info = xtd::diagnostics::stack_frame::empty()) {if (value == static_cast(0)) throw argument_out_of_range_exception {string::format("{} ('0') must be a non-zero value. (Parameter '{}')\nActual value was 0.", value, param_name, info)};} + /// @} + private: const char* default_message() const noexcept {return "Specified argument is out of range of valid values."_t;} };