From 7f597233c943c29744b17760c5e995882b6ad227 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 4 Mar 2015 12:38:45 -0800 Subject: [PATCH] better exception when boost regex cannot initialize ICU support - closes #2722 --- src/expression.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/expression.cpp b/src/expression.cpp index c8798774b..ffa55ddb1 100644 --- a/src/expression.cpp +++ b/src/expression.cpp @@ -40,18 +40,29 @@ expression_ptr parse_expression(std::string const& str) auto node = std::make_shared(); std::string::const_iterator itr = str.begin(); std::string::const_iterator end = str.end(); - try { - bool r = boost::spirit::qi::phrase_parse(itr, end, g, space, *node); - if (r && itr == end) + bool r = false; + try + { + r = boost::spirit::qi::phrase_parse(itr, end, g, space, *node); + } + catch (std::exception const& ex) + { + if (std::string("boost::spirit::qi::expectation_failure") == std::string(ex.what())) { - return node; + // no need to show "boost::spirit::qi::expectation_failure" which is a std::runtime_error + throw config_error("Failed to parse expression: \"" + str + "\""); } else { - throw config_error("Failed to parse expression: \"" + str + "\""); + // show "Could not initialize ICU resources" from boost::regex which is a std::runtime_error + throw config_error(std::string(ex.what()) + " for expression: \"" + str + "\""); } } - catch (std::exception const&) // boost::spirit::qi::expectation_failure + if (r && itr == end) + { + return node; + } + else { throw config_error("Failed to parse expression: \"" + str + "\""); }