Put error message into exception instead of std::cerr

This commit is contained in:
Stephan van Veen 2019-05-11 12:41:57 +02:00
parent 603e87ae69
commit 8dd508d4b6

View File

@ -110,16 +110,11 @@ public:
*/
void validate() const {
if (mIsOptional) {
if (mIsUsed && mNumArgs > 0) {
if (mValues.size() != mNumArgs) {
// All cool if there's a default value to return
// If no default value, then there's a problem
if (!mDefaultValue.has_value()) {
std::cout << "error: " << mUsedName << ": expected " << mNumArgs << " argument(s). "
if (mIsUsed && mValues.size() != mNumArgs && !mDefaultValue.has_value()) {
std::stringstream stream;
stream << "error: " << mUsedName << ": expected " << mNumArgs << " argument(s). "
<< mValues.size() << " provided.\n" << std::endl;
throw std::runtime_error("wrong number of arguments");
}
}
throw std::runtime_error(stream.str());
}
else {
// TODO: check if an implicit value was programmed for this argument
@ -127,9 +122,10 @@ public:
}
else {
if (mValues.size() != mNumArgs) {
std::cout << "error: " << mUsedName << ": expected " << mNumArgs << " argument(s). "
std::stringstream stream;
stream << "error: " << mUsedName << ": expected " << mNumArgs << " argument(s). "
<< mValues.size() << " provided.\n" << std::endl;
throw std::runtime_error("wrong number of arguments");
throw std::runtime_error(stream.str());
}
}
}