diff --git a/src/ArgParser.cc b/src/ArgParser.cc index 316c9c2..858b579 100644 --- a/src/ArgParser.cc +++ b/src/ArgParser.cc @@ -76,9 +76,9 @@ void ArgParser::parse(int argc, char ** argv) const longopts.push_back({0,0,0,0}); { + opterr = 1; int r; int idx; - opterr = 0; while(true) { r = getopt_long(argc, argv, &optstring.front(), &longopts.front(), &idx); @@ -87,9 +87,7 @@ void ArgParser::parse(int argc, char ** argv) const assert(r != ':'); if(r == '?') { - ostringstream sout; - assert(optopt < 256); - throw string() + ((opt_map.find(optopt) == opt_map.end()) ? "Unknown option: -" : "Missing argument for option -") + (char)optopt; + throw ""; } auto iter = opt_map.find(r); diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index f76b009..228ecb4 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -89,10 +89,24 @@ void parse_options (int argc, char **argv) { argparser.parse(argc, argv); } + catch(const char * s) + { + // if s == "", getopt_long would have printed the error message + if(s && s[0]) + { + cerr << "Error when parsing the arguments:" << endl; + cerr << s << endl; + } + exit(EXIT_FAILURE); + } catch(const std::string & s) { - cerr << "Error when parsing the arguments:" << endl; - cerr << s << endl; + // if s == "", getopt_long would have printed the error message + if(s != "") + { + cerr << "Error when parsing the arguments:" << endl; + cerr << s << endl; + } exit(EXIT_FAILURE); } } @@ -181,6 +195,10 @@ int main(int argc, char **argv) finished = true; } + catch (const char * s) + { + cerr << "Error: " << s << endl; + } catch (const string & s) { cerr << "Error: " << s << endl;