From f08a280f92afbd0dac7dfc213d3e5345538a1632 Mon Sep 17 00:00:00 2001 From: Stephan van Veen Date: Mon, 13 May 2019 22:29:09 +0200 Subject: [PATCH] Throw std::logic_error instead of returning empty value --- include/argparse.hpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index d92ddba..4313c8b 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -304,7 +304,7 @@ class ArgumentParser { if (tIterator != mArgumentMap.end()) { return tIterator->second->get(); } - return T(); + throw std::logic_error("No such argument"); } // Indexing operator. Return a reference to an Argument object @@ -314,9 +314,7 @@ class ArgumentParser { if (tIterator != mArgumentMap.end()) { return *(tIterator->second); } - else { - throw std::runtime_error("Argument " + aArgumentName + " not found"); - } + throw std::logic_error("No such argument"); } // Printing the one and only help message @@ -390,12 +388,6 @@ class ArgumentParser { } 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 */