From 9aeac71b9bec3b90001642833fab44bdb45d786d Mon Sep 17 00:00:00 2001 From: Hannes Hauswedell Date: Tue, 21 Nov 2023 21:57:33 +0100 Subject: [PATCH] [fix] exception handling of the sharg-parser --- src/mkindex.cpp | 14 ++++++++++++++ src/search.cpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/mkindex.cpp b/src/mkindex.cpp index 5de6b079e..566e61036 100644 --- a/src/mkindex.cpp +++ b/src/mkindex.cpp @@ -68,7 +68,21 @@ void realMain(LambdaIndexerOptions const & options); int mkindexMain(int const argc, char const ** argv) { LambdaIndexerOptions options; + +#ifdef NDEBUG + try + { + parseCommandLine(options, argc, argv); + } + catch (sharg::parser_error const & ext) // catch user errors + { + std::cerr << "\n\nERROR: during command line parsing\n" + << " \"" << ext.what() << "\"\n"; + return -1; + } +#else parseCommandLine(options, argc, argv); +#endif #ifdef NDEBUG try diff --git a/src/search.cpp b/src/search.cpp index a25e94a8c..b01b504b1 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -73,7 +73,21 @@ void realMain(LambdaOptions const & options); int searchMain(int const argc, char const ** argv) { LambdaOptions options; + +#ifdef NDEBUG + try + { + parseCommandLine(options, argc, argv); + } + catch (sharg::parser_error const & ext) // catch user errors + { + std::cerr << "\n\nERROR: during command line parsing\n" + << " \"" << ext.what() << "\"\n"; + return -1; + } +#else parseCommandLine(options, argc, argv); +#endif #ifdef _OPENMP omp_set_num_threads(options.threads - options.lazyQryFile); // reserve one thread for I/O when lazy-loading