]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make read_input print error messages again. 3122/head
authorDavid Wells <wellsd2@rpi.edu>
Fri, 23 Sep 2016 22:26:11 +0000 (18:26 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Wed, 28 Sep 2016 19:30:44 +0000 (15:30 -0400)
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
tests/parameter_handler/parameter_handler_10.cc
tests/parameter_handler/parameter_handler_11.cc
tests/parameter_handler/parameter_handler_1_include_fail.cc
tests/parameter_handler/parameter_handler_20.cc
tests/parameter_handler/parameter_handler_20.output
tests/parameter_handler/parameter_handler_backslash_03.cc
tests/parameter_handler/parameter_handler_backslash_04.cc
tests/parameter_handler/parameter_handler_backslash_05.cc

index 2f8e38bedb40b99d78c232737b98824f3fbbe6a4..485707cf0d8292f221c7888458e9cb30810fe743 100644 (file)
@@ -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;
 }
 
 
index 74fd33fe1b17d3029361bc600730a1606f3ad11f..e4787ac085891c86235eb2bb483c62a9292c4b51 100644 (file)
@@ -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
index 8332e04d229b5f584e2be7ada1d154477210c171..6e654252ac60865f8f76420db20c531bcb743db2 100644 (file)
@@ -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
index 0efd06650783d9f50d3174f669da95f33d8389fc..80344f63c92f6129b4957f14e03971a8cea3a735 100644 (file)
@@ -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)
     {
index cab9682464004912b7f840674458425e7e243e54..aa25b3d4baa522dc0eeda7fb47979a19d7002123 100644 (file)
@@ -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;
     }
 }
 
index 68e6af9fce51c5afa3563234973a2993632dce9c..0f7289b4a4c2a3b377a81e94760b2b9942c37987 100644 (file)
@@ -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
index 02e659a4f0b602f1b2ec68f0bf75a1e3dcd19b20..0b2922ae3ad6e257061d4a00586e45e63e8fbd8b 100644 (file)
@@ -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");
index 750c04c2012899fbad3c54d9483efb253bc3af7d..7361ce6fadb2aed400e66aeddeef1a155ceeb751 100644 (file)
@@ -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;
index 6bdba4c7e9f7f6f604f1fe265a03c290817baee2..253d098b84cc9a7ef47cf2e132a2b909000c5ff5 100644 (file)
@@ -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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.