]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move global deal_II_exceptions variables into the internals namespace 7063/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 17 Aug 2018 09:34:42 +0000 (11:34 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 17 Aug 2018 09:34:42 +0000 (11:34 +0200)
include/deal.II/base/exceptions.h
source/base/exceptions.cc
tests/tests.h

index a929f1d5c3d184b21a0b04df0a5b9f5245967325..0c20aacc573b37127463ec42131709385725828d 100644 (file)
@@ -1020,14 +1020,17 @@ namespace StandardExceptions
  */
 namespace deal_II_exceptions
 {
-  /**
-   * Setting this variable to false will disable deal.II's exception mechanism
-   * to abort the problem. The Assert() macro will throw the exception instead
-   * and the AssertNothrow() macro will just print the error message. This
-   * variable should not be changed directly. Use disable_abort_on_exception()
-   * instead.
-   */
-  extern bool allow_abort_on_exception;
+  namespace internals
+  {
+    /**
+     * Setting this variable to false will disable deal.II's exception mechanism
+     * to abort the problem. The Assert() macro will throw the exception instead
+     * and the AssertNothrow() macro will just print the error message. This
+     * variable should not be changed directly. Use disable_abort_on_exception()
+     * instead.
+     */
+    extern bool allow_abort_on_exception;
+  } // namespace internals
 
   /**
    * Set a string that is printed upon output of the message indicating a
@@ -1093,7 +1096,7 @@ namespace deal_II_exceptions
      * error message provided by @p exc and calling <tt>std::abort()</tt>.
      */
     [[noreturn]] void
-    internal_abort(const ExceptionBase &exc) noexcept;
+    abort(const ExceptionBase &exc) noexcept;
 
     /**
      * An enum describing how to treat an exception in issue_error_noreturn.
@@ -1105,7 +1108,7 @@ namespace deal_II_exceptions
        * deal_II_exceptions::disable_abort_on_exception has been called: in
        * that case the program will throw an exception.
        */
-      try_abort_on_exception,
+      abort_or_throw_on_exception,
       /**
        * Throw the exception normally.
        */
@@ -1115,7 +1118,7 @@ namespace deal_II_exceptions
     /**
      * This routine does the main work for the exception generation mechanism
      * used in the <tt>Assert</tt> and <tt>AssertThrow</tt> macros: as the
-     * name implies, this function either ends throwing an exception (if
+     * name implies, this function either ends by throwing an exception (if
      * @p handling is throw_on_exception, or @p handling is try_abort_exception
      * and deal_II_exceptions::disable_abort_on_exception is false) or with a
      * call to <tt>abort</tt> (if @p handling is try_abort_exception and
@@ -1143,10 +1146,11 @@ namespace deal_II_exceptions
 
       switch (handling)
         {
-          case try_abort_on_exception:
+          case abort_or_throw_on_exception:
             {
-              if (dealii::deal_II_exceptions::allow_abort_on_exception)
-                internals::internal_abort(e);
+              if (dealii::deal_II_exceptions::internals::
+                    allow_abort_on_exception)
+                internals::abort(e);
               else
                 {
                   // We are not allowed to abort, so just throw the error:
@@ -1232,30 +1236,32 @@ namespace deal_II_exceptions
  */
 #ifdef DEBUG
 #  ifdef DEAL_II_HAVE_BUILTIN_EXPECT
-#    define Assert(cond, exc)                                                \
-      {                                                                      \
-        if (__builtin_expect(!(cond), false))                                \
-          ::dealii::deal_II_exceptions::internals::issue_error_noreturn(     \
-            ::dealii::deal_II_exceptions::internals::try_abort_on_exception, \
-            __FILE__,                                                        \
-            __LINE__,                                                        \
-            __PRETTY_FUNCTION__,                                             \
-            #cond,                                                           \
-            #exc,                                                            \
-            exc);                                                            \
+#    define Assert(cond, exc)                                            \
+      {                                                                  \
+        if (__builtin_expect(!(cond), false))                            \
+          ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \
+            ::dealii::deal_II_exceptions::internals::                    \
+              abort_or_throw_on_exception,                               \
+            __FILE__,                                                    \
+            __LINE__,                                                    \
+            __PRETTY_FUNCTION__,                                         \
+            #cond,                                                       \
+            #exc,                                                        \
+            exc);                                                        \
       }
 #  else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
-#    define Assert(cond, exc)                                                \
-      {                                                                      \
-        if (!(cond))                                                         \
-          ::dealii::deal_II_exceptions::internals::issue_error_noreturn(     \
-            ::dealii::deal_II_exceptions::internals::try_abort_on_exception, \
-            __FILE__,                                                        \
-            __LINE__,                                                        \
-            __PRETTY_FUNCTION__,                                             \
-            #cond,                                                           \
-            #exc,                                                            \
-            exc);                                                            \
+#    define Assert(cond, exc)                                            \
+      {                                                                  \
+        if (!(cond))                                                     \
+          ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \
+            ::dealii::deal_II_exceptions::internals::                    \
+              abort_or_throw_on_exception,                               \
+            __FILE__,                                                    \
+            __LINE__,                                                    \
+            __PRETTY_FUNCTION__,                                         \
+            #cond,                                                       \
+            #exc,                                                        \
+            exc);                                                        \
       }
 #  endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
 #else
index 753f144b2997315ecff5d81787e595097c945a04..817bd1cd68f346e62d412d6f1ad496c5983dc606 100644 (file)
@@ -41,30 +41,32 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace deal_II_exceptions
 {
-  std::string additional_assert_output;
+  namespace internals
+  {
+    std::string additional_assert_output;
+
+    bool show_stacktrace = true;
+
+    bool allow_abort_on_exception = true;
+  } // namespace internals
 
   void
   set_additional_assert_output(const char *const p)
   {
-    additional_assert_output = p;
+    internals::additional_assert_output = p;
   }
 
-  bool show_stacktrace = true;
-
   void
   suppress_stacktrace_in_exceptions()
   {
-    show_stacktrace = false;
+    internals::show_stacktrace = false;
   }
 
-  bool allow_abort_on_exception = true;
-
   void
   disable_abort_on_exception()
   {
-    allow_abort_on_exception = false;
+    internals::allow_abort_on_exception = false;
   }
-
 } // namespace deal_II_exceptions
 
 
@@ -219,7 +221,7 @@ ExceptionBase::print_stack_trace(std::ostream &out) const
   if (n_stacktrace_frames == 0)
     return;
 
-  if (deal_II_exceptions::show_stacktrace == false)
+  if (deal_II_exceptions::internals::show_stacktrace == false)
     return;
 
   // if there is a stackframe stored, print it
@@ -322,12 +324,13 @@ ExceptionBase::generate_message() const
       print_info(converter);
       print_stack_trace(converter);
 
-      if (!deal_II_exceptions::additional_assert_output.empty())
+      if (!deal_II_exceptions::internals::additional_assert_output.empty())
         {
           converter
             << "--------------------------------------------------------"
             << std::endl
-            << deal_II_exceptions::additional_assert_output << std::endl;
+            << deal_II_exceptions::internals::additional_assert_output
+            << std::endl;
         }
 
       converter << "--------------------------------------------------------"
@@ -402,7 +405,7 @@ namespace deal_II_exceptions
   namespace internals
   {
     [[noreturn]] void
-    internal_abort(const ExceptionBase &exc) noexcept
+    abort(const ExceptionBase &exc) noexcept
     {
       // first print the error
       std::cerr << exc.what() << std::endl;
@@ -450,8 +453,8 @@ namespace deal_II_exceptions
     void
     do_issue_error_nothrow(const ExceptionBase &exc) noexcept
     {
-      if (dealii::deal_II_exceptions::allow_abort_on_exception)
-        internal_abort(exc);
+      if (deal_II_exceptions::internals::allow_abort_on_exception)
+        abort(exc);
       else
         {
           // We are not allowed to throw, and not allowed to abort.
index a3e2266953e97154d70817cd4abb719902406fc8..25ccf10ff5f26da4ae8499e2da9b452c78abfe43 100644 (file)
@@ -601,7 +601,10 @@ struct MPILogInitAll
 DEAL_II_NAMESPACE_OPEN
 namespace deal_II_exceptions
 {
-  extern bool show_stacktrace;
+  namespace internals
+  {
+    extern bool show_stacktrace;
+  }
 } // namespace deal_II_exceptions
 DEAL_II_NAMESPACE_CLOSE
 
@@ -619,8 +622,8 @@ new_tbb_assertion_handler(const char *file,
   std::cerr << "Detailed description: " << comment << std::endl;
 
   // Reenable abort and stacktraces:
-  deal_II_exceptions::allow_abort_on_exception = true;
-  deal_II_exceptions::show_stacktrace          = true;
+  deal_II_exceptions::internals::allow_abort_on_exception = true;
+  deal_II_exceptions::internals::show_stacktrace          = true;
 
   // And abort with a deal.II exception:
   Assert(false, ExcMessage("TBB Exception, see above"));

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.