Create a exception to thow when Options not exists

When the user try to get a option that not exist, cxxopt library
throw a std::domain_error, that make a segfaults. See #185.

On this PR I create a new Exception class from OptionParseException
that is throw when this situation occur. This avoid the SegFaults
error.
This commit is contained in:
eamanu 2019-06-24 19:11:53 -03:00
parent e6858d3429
commit b762e3faec

View File

@ -394,6 +394,15 @@ namespace cxxopts
}
};
class option_value_not_exists_exception : public OptionParseException
{
public:
option_value_not_exists_exception()
: OptionParseException("Option value does not exist")
{
}
};
class missing_argument_exception : public OptionParseException
{
public:
@ -1068,7 +1077,7 @@ namespace cxxopts
as() const
{
if (m_value == nullptr) {
throw std::domain_error("No value");
throw option_value_not_exists_exception();
}
#ifdef CXXOPTS_NO_RTTI