diff --git a/src/cxxopts.cpp b/src/cxxopts.cpp index fb43c25..fa6146c 100644 --- a/src/cxxopts.cpp +++ b/src/cxxopts.cpp @@ -91,6 +91,7 @@ Options::parse(int& argc, char**& argv) if (iter == m_short.end()) { + throw option_not_exists_exception(name); //argument not found } @@ -111,6 +112,7 @@ Options::parse(int& argc, char**& argv) else { //error + throw option_requires_argument_exception(name); } } } @@ -123,6 +125,7 @@ Options::parse(int& argc, char**& argv) if (iter == m_long.end()) { + throw option_not_exists_exception(name); } auto opt = iter->second; diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index f45cf0b..90b4148 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -98,6 +98,24 @@ namespace cxxopts } }; + class option_not_exists_exception : public OptionParseException + { + public: + option_not_exists_exception(const std::string& option) + : OptionParseException(u8"Option ‘" + option + u8"’ does not exist") + { + } + }; + + class option_requires_argument_exception : public OptionParseException + { + public: + option_requires_argument_exception(const std::string& option) + : OptionParseException(u8"Option ‘" + option + u8"’ requires an argument") + { + } + }; + class OptionAdder; class OptionDetails