Throw std::logic_error instead of returning empty value

This commit is contained in:
Stephan van Veen 2019-05-13 22:29:09 +02:00
parent 02b3ed1878
commit f08a280f92

View File

@ -304,7 +304,7 @@ class ArgumentParser {
if (tIterator != mArgumentMap.end()) { if (tIterator != mArgumentMap.end()) {
return tIterator->second->get<T>(); return tIterator->second->get<T>();
} }
return T(); throw std::logic_error("No such argument");
} }
// Indexing operator. Return a reference to an Argument object // Indexing operator. Return a reference to an Argument object
@ -314,9 +314,7 @@ class ArgumentParser {
if (tIterator != mArgumentMap.end()) { if (tIterator != mArgumentMap.end()) {
return *(tIterator->second); return *(tIterator->second);
} }
else { throw std::logic_error("No such argument");
throw std::runtime_error("Argument " + aArgumentName + " not found");
}
} }
// Printing the one and only help message // Printing the one and only help message
@ -390,12 +388,6 @@ class ArgumentParser {
} }
private: private:
// If the argument was defined by the user and can be found in mArgumentMap, then it's valid
bool is_valid_argument(const std::string& aName) {
auto tIterator = mArgumentMap.find(aName);
return (tIterator != mArgumentMap.end());
}
/* /*
* @throws std::runtime_error in case of any invalid argument * @throws std::runtime_error in case of any invalid argument
*/ */