From f7bc43b662bfef270b40e26df03a72b7d4f2027f Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Sun, 20 May 2018 21:30:08 +0200 Subject: [PATCH] [BL] ConfigTree: Fix warning "catch by value". --- BaseLib/ConfigTree-impl.h | 18 ++++++++++++------ BaseLib/ConfigTreeUtil.cpp | 11 +++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/BaseLib/ConfigTree-impl.h b/BaseLib/ConfigTree-impl.h index 39f8eba0215..4256d180a8d 100644 --- a/BaseLib/ConfigTree-impl.h +++ b/BaseLib/ConfigTree-impl.h @@ -120,14 +120,20 @@ peekConfigParameter(std::string const& param) const { checkKeyname(param); - if (auto p =_tree->get_child_optional(param)) { - try { + if (auto p = _tree->get_child_optional(param)) + { + try + { return p->get_value<T>(); - } catch (boost::property_tree::ptree_bad_data) { - error("Value for key <" + param + "> `" + shortString(p->data()) - + "' not convertible to the desired type."); } - } else { + catch (boost::property_tree::ptree_bad_data const&) + { + error("Value for key <" + param + "> `" + shortString(p->data()) + + "' not convertible to the desired type."); + } + } + else + { error("Key <" + param + "> has not been found"); } } diff --git a/BaseLib/ConfigTreeUtil.cpp b/BaseLib/ConfigTreeUtil.cpp index d6f0c74e5ed..e64f8ae4dbc 100644 --- a/BaseLib/ConfigTreeUtil.cpp +++ b/BaseLib/ConfigTreeUtil.cpp @@ -54,13 +54,16 @@ makeConfigTree(const std::string& filepath, const bool be_ruthless, // note: Trimming whitespace and ignoring comments is crucial in order // for our configuration tree implementation to work! - try { + try + { read_xml(filepath, ptree, boost::property_tree::xml_parser::no_comments | - boost::property_tree::xml_parser::trim_whitespace); - } catch (boost::property_tree::xml_parser_error e) { + boost::property_tree::xml_parser::trim_whitespace); + } + catch (boost::property_tree::xml_parser_error const& e) + { OGS_FATAL("Error while parsing XML file `%s' at line %lu: %s.", - e.filename().c_str(), e.line(), e.message().c_str()); + e.filename().c_str(), e.line(), e.message().c_str()); } DBUG("Project configuration from file \'%s\' read.", filepath.c_str()); -- GitLab