Move GetOpt exception handling to the .cpp file
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Apr 2013 12:57:45 +0000 (15:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Apr 2013 12:57:45 +0000 (15:57 +0300)
source/core/getopt.cpp
source/core/getopt.h

index 34e53172aeb194d1cebc29c7df4de8719add8c27..ad726448589cc0ebc38255cd7790cdbbaf0e0136 100644 (file)
@@ -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
index 2aaceef836730aa24a966c3cfaa20bb9864e23a7..53c9ddf2f0100681099df40466e125914e5e74b3 100644 (file)
@@ -122,16 +122,7 @@ private:
                virtual void store() { }
 
                virtual void store(const std::string &a)
-               {
-                       try
-                       {
-                               data = lexical_cast<T>(a);
-                       }
-                       catch(const lexical_error &e)
-                       {
-                               throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")");
-                       }
-               }
+               { data = lexical_cast<T>(a); }
        };
 
        template<typename T>
@@ -147,16 +138,7 @@ private:
                virtual void store() { }
 
                virtual void store(const std::string &a)
-               {
-                       try
-                       {
-                               data.push_back(lexical_cast<typename T::value_type>(a));
-                       }
-                       catch(const lexical_error &e)
-                       {
-                               throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")");
-                       }
-               }
+               { data.push_back(lexical_cast<typename T::value_type>(a)); }
        };
 
        bool help;