From 24184849b23bb566f5d8a56ec52f1da0c379a75b Mon Sep 17 00:00:00 2001
From: David Wells <wellsd2@rpi.edu>
Date: Thu, 15 Sep 2016 20:02:23 -0400
Subject: [PATCH] Clarify error handling with PathSearch/read_input.

This commit keeps the same control flow if one tries to use this
function to write out default values to a file but gets rid of the
std::cerr messages (like the recent changes to read_input).
---
 include/deal.II/base/parameter_handler.h      | 23 ++++++++++++++++---
 source/base/parameter_handler.cc              | 14 ++++++++++-
 .../parameter_handler/parameter_handler_18.cc |  3 +--
 3 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/include/deal.II/base/parameter_handler.h b/include/deal.II/base/parameter_handler.h
index 3134e84db7..f395c5e463 100644
--- a/include/deal.II/base/parameter_handler.h
+++ b/include/deal.II/base/parameter_handler.h
@@ -1655,8 +1655,6 @@ public:
    * Read input from a file the name of which is given. The PathSearch class
    * "PARAMETERS" is used to find the file.
    *
-   * Return whether the read was successful.
-   *
    * Unless <tt>optional</tt> is <tt>true</tt>, this function will
    * automatically generate the requested file with default values if the file
    * did not exist. This file will not contain additional comments if
@@ -1665,11 +1663,30 @@ public:
    * If non-empty @p last_line is provided, the ParameterHandler object
    * will stop parsing lines after encountering @p last_line .
    * This is handy when adding extra data that shall be parsed manually.
+   *
+   * @deprecated This function has been deprecated in favor of the replacement
+   * ParameterHandler::parse_input, which raises exceptions to indicate errors
+   * instead of returning an error code. ParameterHandler::parse_input does
+   * not have the capability to write default values to a file on failure: if
+   * you wish to duplicate that old behavior then you should catch the
+   * PathSearch::ExcFileNotFound exception and then call
+   * ParameterHandler::print_parameters.
    */
   virtual bool read_input (const std::string &filename,
                            const bool optional = false,
                            const bool write_stripped_file = false,
-                           const std::string &last_line = "");
+                           const std::string &last_line = "") DEAL_II_DEPRECATED;
+
+  /**
+   * Parse the given file to provide values for known parameter fields. The
+   * PathSearch class "PARAMETERS" is used to find the file.
+   *
+   * If non-empty @p last_line is provided, the ParameterHandler object
+   * will stop parsing lines after encountering @p last_line .
+   * This is handy when adding extra data that shall be parsed manually.
+   */
+  virtual void parse_input (const std::string &filename,
+                            const std::string &last_line = "");
 
   /**
    * Read input from a string in memory. The lines in memory have to be
diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc
index 2dc356d68c..2f8e38bedb 100644
--- a/source/base/parameter_handler.cc
+++ b/source/base/parameter_handler.cc
@@ -1730,7 +1730,7 @@ bool ParameterHandler::read_input (const std::string &filename,
       std::ifstream file_stream (openname.c_str());
       AssertThrow(file_stream, ExcIO());
 
-      parse_input (file_stream, filename, last_line);
+      return read_input (file_stream, filename, last_line);
     }
   catch (const PathSearch::ExcFileNotFound &)
     {
@@ -1750,6 +1750,18 @@ bool ParameterHandler::read_input (const std::string &filename,
 
 
 
+void ParameterHandler::parse_input (const std::string &filename,
+                                    const std::string &last_line)
+{
+  PathSearch search("PARAMETERS");
+
+  std::string openname = search.find(filename);
+  std::ifstream file_stream (openname.c_str());
+  parse_input (file_stream, filename, last_line);
+}
+
+
+
 bool
 ParameterHandler::read_input_from_string (const char *s,
                                           const std::string &last_line)
diff --git a/tests/parameter_handler/parameter_handler_18.cc b/tests/parameter_handler/parameter_handler_18.cc
index 1b56b842b9..a07c739439 100644
--- a/tests/parameter_handler/parameter_handler_18.cc
+++ b/tests/parameter_handler/parameter_handler_18.cc
@@ -34,8 +34,7 @@ void test ()
   foo.declare_entry("val", "1.0", dealii::Patterns::Double(), "");
   foo.leave_subsection();
 
-  bool okay = foo.read_input(SOURCE_DIR "/parameter_handler_18.prm");
-  Assert(okay, ExcMessage("read_input failed"));
+  foo.parse_input(SOURCE_DIR "/parameter_handler_18.prm");
 
   foo.enter_subsection("bar");
   deallog << foo.get ("val") << std::endl;
-- 
2.39.5