]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce DeclExceptionMsg.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sat, 28 Feb 2015 03:45:04 +0000 (21:45 -0600)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 1 Mar 2015 02:32:53 +0000 (20:32 -0600)
doc/news/changes.h
include/deal.II/base/exceptions.h

index 692cd913d093435f03ab66c51dd3d655c14cfe5a..293e9d7711ba613567e76a57ccf9a05d49ac4cc3 100644 (file)
@@ -351,6 +351,13 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li> New: There is now a new macro DeclExceptionMsg that allows to
+  declare an exception that does not take any run-time arguments
+  yet still allows to specify an error message.
+  <br>
+  (Wolfgang Bangerth, 2015/02/27)
+  </li>
+
   <li> New: There is now a class std_cxx11::unique_ptr that provides
   the functionality of std::unique_ptr in C++11 mode, and that
   provides an emulation for older compilers.
index 1993bb285d78147aabfeaf6769b5c8ad6836bfae..86aa24c8bfef5d263bcf215e704c6075d844d9c3 100644 (file)
@@ -376,6 +376,27 @@ namespace deal_II_exceptions
   class Exception0 :  public dealii::ExceptionBase {}
 
 
+/**
+ * Declare an exception class derived from ExceptionBase that can take
+ * one runtime argument, but if none is given in the place where you
+ * want to throw the exception, it simply reverts to the default text
+ * provided when declaring the exception class through this macro.
+ *
+ * @ingroup Exceptions
+ */
+#define DeclExceptionMsg(Exception, defaulttext)                          \
+  class Exception :  public dealii::ExceptionBase                         \
+  {                                                                       \
+  public:                                                                 \
+    Exception (const std::string &msg = defaulttext) : arg (msg) {}       \
+    virtual ~Exception () throw () {}                                     \
+    virtual void print_info (std::ostream &out) const {                   \
+      out << arg << std::endl;                                            \
+    }                                                                     \
+  private:                                                                \
+    const std::string arg;                                                \
+  }
+
 /**
  * Declare an exception class derived from ExceptionBase with one additional
  * parameter.
@@ -499,6 +520,16 @@ namespace deal_II_exceptions
 #define DeclException0(Exception0)                                        \
   static dealii::ExceptionBase& Exception0 ()
 
+/**
+ * Declare an exception class derived from ExceptionBase that can take
+ * one runtime argument, but if none is given in the place where you
+ * want to throw the exception, it simply reverts to the default text
+ * provided when declaring the exception class through this macro.
+ *
+ * @ingroup Exceptions
+ */
+#define DeclExceptionMsg(Exception, defaulttext)                          \
+  static dealii::ExceptionBase& Exception ()
 
 /**
  * Declare an exception class derived from ExceptionBase with one additional

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.