xtd 0.2.0
argument_exception.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "literals.hpp"
7
9namespace xtd {
25 public:
27
32 explicit argument_exception(const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : system_exception(default_message(), stack_frame) {}
41 explicit argument_exception(const xtd::string& message, const std::error_code& error, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : system_exception(message, error, stack_frame) {}
51 explicit argument_exception(const xtd::string& message, const std::error_code& error, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : system_exception(message, error, help_link, stack_frame) {}
56 explicit argument_exception(const std::exception& inner_exception, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : system_exception(default_message(), inner_exception, stack_frame) {}
67 explicit argument_exception(const xtd::string& message, const std::exception& inner_exception, const std::error_code& error, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : system_exception(message, inner_exception, error, stack_frame) {}
80 explicit argument_exception(const xtd::string& message, const std::exception& inner_exception, const std::error_code& error, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : system_exception(message, inner_exception, error, help_link, stack_frame) {}
82
84 argument_exception(const argument_exception&) = default;
85 argument_exception& operator =(const argument_exception&) = default;
87
89
96 static void throw_if_empty(const xtd::string& argument, const xtd::string& param_name = xtd::string::empty_string, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {if (xtd::string::is_empty(argument)) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument, string::format("The value cannot be an empty string. (Parameter '{}')", param_name, stack_frame).c_str());}
102 static void throw_if_empty_or_white_space(const xtd::string& argument, const xtd::string& param_name = xtd::string::empty_string, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {if (xtd::string::is_empty(argument.replace(" ", ""))) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument, string::format("The value cannot be an empty string or composed entirely of whitespace. (Parameter '{}')", param_name, stack_frame).c_str());}
104
105 private:
106 const char* default_message() const noexcept {return "Value does not fall within the expected range."_t;}
107 };
108}
The exception that is thrown when one of the arguments provided to a method is not valid.
Definition argument_exception.hpp:24
argument_exception(const xtd::string &message, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:46
argument_exception(const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:32
static void throw_if_empty(const xtd::string &argument, const xtd::string &param_name=xtd::string::empty_string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Throws an exception if argument is empty.
Definition argument_exception.hpp:96
argument_exception(const std::exception &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:56
argument_exception(const xtd::string &message, const std::error_code &error, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:41
argument_exception(const xtd::string &message, const std::error_code &error, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:51
argument_exception(const xtd::string &message, const std::exception &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:61
argument_exception(const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:36
static void throw_if_empty_or_white_space(const xtd::string &argument, const xtd::string &param_name=xtd::string::empty_string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Throws an exception if argument is empty, or consists only of white-space characters.
Definition argument_exception.hpp:102
argument_exception(const xtd::string &message, const std::exception &inner_exception, const std::error_code &error, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:80
argument_exception(const xtd::string &message, const std::exception &inner_exception, const std::error_code &error, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:67
argument_exception(const xtd::string &message, const std::exception &inner_exception, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Create a new instance of class argument_exception.
Definition argument_exception.hpp:73
Represents text as a sequence of character units.
Definition basic_string.hpp:71
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.hpp:116
bool is_empty() const noexcept
Indicates whether this basic_string is an empty basic_string ("").
Definition basic_string.hpp:1503
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:48
static stack_frame current(const xtd::diagnostics::source_location &value=xtd::diagnostics::source_location::current()) noexcept
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
virtual const xtd::string & message() const noexcept
Gets message associate to the exception.
virtual exception_ref inner_exception() const noexcept
Gets the exception instance that caused the current exception.
virtual const xtd::string & help_link() const noexcept
Gets a link to the help file associated with this exception.
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
@ argument
The argument is not valid.
Contains xtd literals.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::system_exception exception.