From 9c6c946ed658abd50be9d597cb2c722592d660ae Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 30 Apr 2013 15:57:45 +0300 Subject: [PATCH] Move GetOpt exception handling to the .cpp file --- source/core/getopt.cpp | 20 ++++++++++++++++++-- source/core/getopt.h | 22 ++-------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index 34e5317..ad72644 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -257,22 +257,38 @@ void GetOpt::OptBase::process() { if(arg_type==REQUIRED_ARG) throw usage_error("--"+lng+" requires an argument"); + ++seen_count; if(ext_seen_count) *ext_seen_count = seen_count; - store(); + try + { + store(); + } + catch(const exception &e) + { + throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")"); + } } void GetOpt::OptBase::process(const string &arg) { if(arg_type==NO_ARG) throw usage_error("--"+lng+" takes no argument"); + ++seen_count; if(ext_seen_count) *ext_seen_count = seen_count; - store(arg); + try + { + store(arg); + } + catch(const exception &e) + { + throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")"); + } } } // namespace Msp diff --git a/source/core/getopt.h b/source/core/getopt.h index 2aaceef..53c9ddf 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -122,16 +122,7 @@ private: virtual void store() { } virtual void store(const std::string &a) - { - try - { - data = lexical_cast(a); - } - catch(const lexical_error &e) - { - throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")"); - } - } + { data = lexical_cast(a); } }; template @@ -147,16 +138,7 @@ private: virtual void store() { } virtual void store(const std::string &a) - { - try - { - data.push_back(lexical_cast(a)); - } - catch(const lexical_error &e) - { - throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")"); - } - } + { data.push_back(lexical_cast(a)); } }; bool help; -- 2.43.0