From: Mikko Rasa Date: Tue, 30 Apr 2013 12:57:45 +0000 (+0300) Subject: Move GetOpt exception handling to the .cpp file X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9c6c946ed658abd50be9d597cb2c722592d660ae;p=libs%2Fcore.git Move GetOpt exception handling to the .cpp file --- 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;