]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Change the type of the argument to ExcMessage from char* to std::string.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 14 Dec 2011 20:14:06 +0000 (20:14 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 14 Dec 2011 20:14:06 +0000 (20:14 +0000)
git-svn-id: https://svn.dealii.org/trunk@24828 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/exceptions.h

index 4fd0d9b8eb65019b8fb4ff9d73995712215ad53d..cb8d133bcbc7ebfd4a151910fb81fd374c2fc186 100644 (file)
@@ -73,6 +73,25 @@ enabled due to a missing include file in file
 <h3>Specific improvements</h3>
 
 <ol>
+<li> Changed: The ExcMessage exception class took an argument of
+type <code>char*</code> that was displayed when the exception
+was raised. However, character pointers are awkward to work with
+because (i) they can not easily be composed to contain things like
+file names that are only known at run-time, and (ii) the string
+pointed to by the pointer had to live longer than the local expression
+in which the exception is generated when using the AssertThrow macro
+(because, when we create an exception, the exception object is passed
+up the call stack until we find a catch-clause; at that time, however,
+the scope in which the exception object was created has long been left).
+This restriction made it impossible to construct the message using std::string
+and then just do something like <code>(std::string("file: ")+filename).c_str()</code>.
+<br>
+To remedy this flaw, the type of the argument to ExcMessage has been
+changed to std::string since objects of this type are readily copyable
+and therefore live long enough.
+<br>
+(Wolfgang Bangerth, 2011/12/14)
+
 <li> New: Setting up a class derived from DataPostprocessor required some
 pretty mechanical steps in which one has to overload four member functions.
 For common cases where a postprocessor only computes a single scalar or
index b7354141a9dd9994180096df4fdd4ac253111f38..853c5b382cfd5ee4d2fb05f71011e86fd2ab7ca8 100644 (file)
@@ -20,6 +20,7 @@
 #include <deal.II/base/config.h>
 
 #include <exception>
+#include <string>
 
 // we only need output streams, but older compilers did not provide
 // them in a separate include file
@@ -902,8 +903,10 @@ namespace StandardExceptions
                                   /**
                                    * This exception works around a
                                    * design flaw in the
-                                   * <tt>DeclException0</tt> macro: that
-                                   * does not allow one to specify a
+                                   * <tt>DeclException0</tt> macro:
+                                   * exceptions desclared through
+                                   * DeclException0 
+                                   * do not allow one to specify a
                                    * message that is displayed when
                                    * the exception is raised, as
                                    * opposed to the other exceptions
@@ -912,11 +915,17 @@ namespace StandardExceptions
                                    *
                                    * When throwing this exception,
                                    * you can give a message as a
-                                   * <tt>char*</tt> as argument to the
+                                   * <tt>std::string</tt> as argument to the
                                    * exception that is then
-                                   * displayed.
+                                   * displayed. The argument can, of
+                                   * course, be constructed at run-time,
+                                   * for example including the name of a
+                                   * file that can't be opened, or any
+                                   * other text you may want to assemble
+                                   * from different pieces.
                                    */
-  DeclException1 (ExcMessage, char*,
+  DeclException1 (ExcMessage,
+                 std::string,
                  << arg1);
 
                                   /**

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.