From 847c44d44a162910e24a42c1b47eae8c9c883967 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 27 Feb 2015 21:45:04 -0600 Subject: [PATCH] Introduce DeclExceptionMsg. --- doc/news/changes.h | 7 +++++++ include/deal.II/base/exceptions.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/doc/news/changes.h b/doc/news/changes.h index 692cd913d0..293e9d7711 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -351,6 +351,13 @@ inconvenience this causes.

Specific improvements

    +
  1. 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. +
    + (Wolfgang Bangerth, 2015/02/27) +
  2. +
  3. 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. diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index 1993bb285d..86aa24c8bf 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -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 -- 2.39.5