From f950b8bae38987375193d5073f2e69bcae44c166 Mon Sep 17 00:00:00 2001 From: David Wells Date: Fri, 23 Sep 2016 18:26:11 -0400 Subject: [PATCH] Make read_input print error messages again. This commit partially restores the old behavior of read_input: this function now prints out the exception message and returns false. Previously this function printed all parsing error messages. Some tests expected (see 79e0a380fb) read_input to raise a specific exception message: those were fixed by calling parse_input instead. --- source/base/parameter_handler.cc | 74 +++++++++++++++++-- .../parameter_handler/parameter_handler_10.cc | 2 +- .../parameter_handler/parameter_handler_11.cc | 2 +- .../parameter_handler_1_include_fail.cc | 2 +- .../parameter_handler/parameter_handler_20.cc | 4 +- .../parameter_handler_20.output | 6 +- .../parameter_handler_backslash_03.cc | 8 +- .../parameter_handler_backslash_04.cc | 6 +- .../parameter_handler_backslash_05.cc | 6 +- 9 files changed, 84 insertions(+), 26 deletions(-) diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index 2f8e38bedb..485707cf0d 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -1608,8 +1608,23 @@ bool ParameterHandler::read_input (std::istream &input, const std::string &filename, const std::string &last_line) { - parse_input(input, filename, last_line); - return true; + try + { + parse_input(input, filename, last_line); + return true; + } + catch (const ExcIO &exc) + { + throw; + } + // This catch block more or less duplicates the old behavior of this function, + // which was to print something to stderr for every parsing error (which are + // now exceptions) and then return false. + catch (const ExceptionBase &exc) + { + std::cerr << exc.what() << std::endl; + } + return false; } @@ -1766,8 +1781,23 @@ bool ParameterHandler::read_input_from_string (const char *s, const std::string &last_line) { - parse_input_from_string(s, last_line); - return true; + try + { + parse_input_from_string (s, last_line); + return true; + } + catch (const ExcIO &exc) + { + throw; + } + // This catch block more or less duplicates the old behavior of this function, + // which was to print something to stderr for every parsing error (which are + // now exceptions) and then return false. + catch (const ExceptionBase &exc) + { + std::cerr << exc.what() << std::endl; + } + return false; } @@ -1868,8 +1898,20 @@ namespace bool ParameterHandler::read_input_from_xml(std::istream &in) { - parse_input_from_xml(in); - return true; + try + { + parse_input_from_xml (in); + return true; + } + catch (const ExcIO &exc) + { + throw; + } + catch (const ExceptionBase &exc) + { + std::cerr << exc.what() << std::endl; + } + return false; } @@ -3060,8 +3102,24 @@ MultipleParameterLoop::read_input (std::istream &input, const std::string &filename, const std::string &last_line) { - MultipleParameterLoop::parse_input(input, filename, last_line); - return true; + + try + { + MultipleParameterLoop::parse_input(input, filename, last_line); + return true; + } + catch (const ExcIO &exc) + { + throw; + } + // This catch block more or less duplicates the old behavior of this function, + // which was to print something to stderr for every parsing error (which are + // now exceptions) and then return false. + catch (const ExceptionBase &exc) + { + std::cerr << exc.what() << std::endl; + } + return false; } diff --git a/tests/parameter_handler/parameter_handler_10.cc b/tests/parameter_handler/parameter_handler_10.cc index 74fd33fe1b..e4787ac085 100644 --- a/tests/parameter_handler/parameter_handler_10.cc +++ b/tests/parameter_handler/parameter_handler_10.cc @@ -31,7 +31,7 @@ void check (const char *p) std::ifstream in(p); try { - prm.read_input (in); + prm.parse_input (in); // The first line in the parameter file should not match the given // pattern, so we should not get here diff --git a/tests/parameter_handler/parameter_handler_11.cc b/tests/parameter_handler/parameter_handler_11.cc index 8332e04d22..6e654252ac 100644 --- a/tests/parameter_handler/parameter_handler_11.cc +++ b/tests/parameter_handler/parameter_handler_11.cc @@ -31,7 +31,7 @@ void check (const char *p) std::ifstream in(p); try { - prm.read_input (in); + prm.parse_input (in); // The first line in the parameter file should not match the given // pattern, so we should not get here diff --git a/tests/parameter_handler/parameter_handler_1_include_fail.cc b/tests/parameter_handler/parameter_handler_1_include_fail.cc index 0efd066507..80344f63c9 100644 --- a/tests/parameter_handler/parameter_handler_1_include_fail.cc +++ b/tests/parameter_handler/parameter_handler_1_include_fail.cc @@ -32,7 +32,7 @@ void check (const char *p) std::ifstream in(p); try { - prm.read_input (in); + prm.parse_input (in); } catch (ParameterHandler::ExcCannotOpenIncludeStatementFile &exc) { diff --git a/tests/parameter_handler/parameter_handler_20.cc b/tests/parameter_handler/parameter_handler_20.cc index cab9682464..aa25b3d4ba 100644 --- a/tests/parameter_handler/parameter_handler_20.cc +++ b/tests/parameter_handler/parameter_handler_20.cc @@ -36,7 +36,7 @@ void check (const char *content) try { - foo.read_input(ss); + foo.parse_input(ss); deallog << "input: "; foo.enter_subsection("bar"); deallog << foo.get_double ("val") << " "; @@ -46,7 +46,7 @@ void check (const char *content) catch (ParameterHandler::ExcCannotParseLine &) { - deallog << "read_input() failed" << std::endl; + deallog << "parse_input() failed" << std::endl; } } diff --git a/tests/parameter_handler/parameter_handler_20.output b/tests/parameter_handler/parameter_handler_20.output index 68e6af9fce..0f7289b4a4 100644 --- a/tests/parameter_handler/parameter_handler_20.output +++ b/tests/parameter_handler/parameter_handler_20.output @@ -4,8 +4,8 @@ DEAL::input: 1.00000 2.00000 DEAL::* check DEAL::input: 1.00000 2.00000 DEAL::* check -DEAL::read_input() failed +DEAL::parse_input() failed DEAL::* check -DEAL::read_input() failed +DEAL::parse_input() failed DEAL::* check -DEAL::read_input() failed +DEAL::parse_input() failed diff --git a/tests/parameter_handler/parameter_handler_backslash_03.cc b/tests/parameter_handler/parameter_handler_backslash_03.cc index 02e659a4f0..0b2922ae3a 100644 --- a/tests/parameter_handler/parameter_handler_backslash_03.cc +++ b/tests/parameter_handler/parameter_handler_backslash_03.cc @@ -50,22 +50,22 @@ int main () // We need a local path for the file to get consistent output messages. const int chdir_return_code = chdir (SOURCE_DIR); AssertThrow (chdir_return_code == 0, ExcInternalError()); - // test both relevant read_input functions. They should fail with a + // test both relevant parse_input functions. They should fail with a // specific exception. try { if (i == 0) { - prm.read_input("prm/parameter_handler_backslash_03.prm"); + prm.parse_input("prm/parameter_handler_backslash_03.prm"); } else { std::ifstream input_stream ("prm/parameter_handler_backslash_03.prm"); - prm.read_input(input_stream); + prm.parse_input(input_stream); } - // read_input should fail and we should not get here + // parse_input should fail and we should not get here std::string list; prm.enter_subsection ("Testing"); list = prm.get ("Function"); diff --git a/tests/parameter_handler/parameter_handler_backslash_04.cc b/tests/parameter_handler/parameter_handler_backslash_04.cc index 750c04c201..7361ce6fad 100644 --- a/tests/parameter_handler/parameter_handler_backslash_04.cc +++ b/tests/parameter_handler/parameter_handler_backslash_04.cc @@ -44,19 +44,19 @@ int main () // We need a local path for the file to get consistent output messages. const int chdir_return_code = chdir (SOURCE_DIR); AssertThrow (chdir_return_code == 0, ExcInternalError()); - // test both relevant read_input functions. They should fail with a + // test both relevant parse_input functions. They should fail with a // specific exception. try { if (i == 0) { - prm.read_input("prm/parameter_handler_backslash_04.prm"); + prm.parse_input("prm/parameter_handler_backslash_04.prm"); } else { std::ifstream input_stream ("prm/parameter_handler_backslash_04.prm"); - prm.read_input(input_stream); + prm.parse_input(input_stream); } std::string list; diff --git a/tests/parameter_handler/parameter_handler_backslash_05.cc b/tests/parameter_handler/parameter_handler_backslash_05.cc index 6bdba4c7e9..253d098b84 100644 --- a/tests/parameter_handler/parameter_handler_backslash_05.cc +++ b/tests/parameter_handler/parameter_handler_backslash_05.cc @@ -53,18 +53,18 @@ int main () // We need a local path for the file to get consistent output messages. const int chdir_return_code = chdir (SOURCE_DIR); AssertThrow (chdir_return_code == 0, ExcInternalError()); - // test both relevant read_input functions + // test both relevant parse_input functions try { if (i == 0) { - prm.read_input("prm/parameter_handler_backslash_05.prm"); + prm.parse_input("prm/parameter_handler_backslash_05.prm"); } else { std::ifstream input_stream ("prm/parameter_handler_backslash_05.prm"); - prm.read_input(input_stream); + prm.parse_input(input_stream); } std::string list_1; -- 2.39.5