Skip to content

Commit

Permalink
Add throw_if_zero method
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Sep 24, 2024
1 parent f9f82c2 commit 5d5ce5d
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/xtd.core/include/xtd/argument_out_of_range_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 <typename value_t>
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<value_t>(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;}
};
Expand Down

0 comments on commit 5d5ce5d

Please sign in to comment.