From: bangerth Date: Wed, 14 Dec 2011 20:14:06 +0000 (+0000) Subject: Change the type of the argument to ExcMessage from char* to std::string. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c73f8713649d5ae94cfc33d2bb93bdb5b2d08cd;p=dealii-svn.git Change the type of the argument to ExcMessage from char* to std::string. git-svn-id: https://svn.dealii.org/trunk@24828 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 4fd0d9b8eb..cb8d133bcb 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -73,6 +73,25 @@ enabled due to a missing include file in file

Specific improvements

    +
  1. Changed: The ExcMessage exception class took an argument of +type char* 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 (std::string("file: ")+filename).c_str(). +
    +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. +
    +(Wolfgang Bangerth, 2011/12/14) +
  2. 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 diff --git a/deal.II/include/deal.II/base/exceptions.h b/deal.II/include/deal.II/base/exceptions.h index b7354141a9..853c5b382c 100644 --- a/deal.II/include/deal.II/base/exceptions.h +++ b/deal.II/include/deal.II/base/exceptions.h @@ -20,6 +20,7 @@ #include #include +#include // 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 - * DeclException0 macro: that - * does not allow one to specify a + * DeclException0 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 - * char* as argument to the + * std::string 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); /**