]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
added disable_abort_on_exception() function to prevent the Assert() macro
authorrschulz <rschulz@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 13 Jul 2005 22:02:07 +0000 (22:02 +0000)
committerrschulz <rschulz@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 13 Jul 2005 22:02:07 +0000 (22:02 +0000)
from calling abort. This change is not yet used in the regression tests,
but this will soon happen...

git-svn-id: https://svn.dealii.org/trunk@11142 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/exceptions.h
deal.II/base/source/exceptions.cc
deal.II/doc/news/changes.html

index b4f284a570f3266c44aeed11a6cb352a85ee5fa2..f0d04f011eaadbcf805013a0538d81bccf46c569 100644 (file)
@@ -509,6 +509,26 @@ namespace deal_II_exceptions
                                    */
   void suppress_stacktrace_in_exceptions ();
   
+                                  /**
+                                   * Calling this function switches off
+                                   * the use of std::abort() when an
+                                   * exception is created using the
+                                   * Assert() macro. Generally, you
+                                   * want to abort the execution of a
+                                   * program when Assert() is called,
+                                    * but it needs to be switched off
+                                   * if you want to log all exceptions
+                                   * created, or if you want to test
+                                   * if an assertion is working
+                                   * correctly. This is done for example
+                                    * in regression tests.
+                                    * Please note that some fatal
+                                   * errors will still call abort(), e.g.
+                                    * when an exception is caught
+                                   * during exception handling
+                                   */
+  void disable_abort_on_exception ();
+
 /**
  * The functions in this namespace are in connection with the Assert
  * and AssertThrow mechanism but are solely for internal purposes and
index 9ab3b9c7ef75790d931ccd2607dc6400214152b5..71bae91229040d666bc12dcc3f98f6125e26e544 100644 (file)
@@ -45,7 +45,15 @@ namespace deal_II_exceptions
   void suppress_stacktrace_in_exceptions ()
   {
     show_stacktrace = false;
-  }  
+  }
+
+
+  bool abort_on_exception = true;
+
+  void disable_abort_on_exception ()
+  {
+    abort_on_exception = false;
+  }
 }
 
 
@@ -155,7 +163,6 @@ void ExceptionBase::print_stack_trace (std::ostream &out) const
 }
 
 
-
 void ExceptionBase::print_exc_data (std::ostream &out) const
 {
   out << "An error occurred in line <" << line
@@ -170,14 +177,12 @@ void ExceptionBase::print_exc_data (std::ostream &out) const
 }
 
 
-
 void ExceptionBase::print_info (std::ostream &out) const
 {
   out << "(none)" << std::endl;
 }
 
 
-
 const char * ExceptionBase::what () const throw ()
 {
                                    // if we say that this function
@@ -235,16 +240,16 @@ const char * ExceptionBase::what () const throw ()
                 << "*** Message is "   << std::endl
                 << exc.what ()         << std::endl
                 << "*** Aborting! ***" << std::endl;
+
       std::abort ();
-      return 0;
     }
   catch (...)
     {
       std::cerr << "*** Exception encountered in exception handling routines ***"
                 << std::endl
                 << "*** Aborting! ***" << std::endl;
+
       std::abort ();
-      return 0;
     }
 }
 
@@ -263,6 +268,7 @@ namespace deal_II_exceptions
                                      * zero.
                                      */
     unsigned int n_treated_exceptions;
+     ExceptionBase *last_exception;
   
 
     void issue_error_assert (const char *file,
@@ -272,16 +278,16 @@ namespace deal_II_exceptions
                             const char *exc_name,
                             ExceptionBase &e)
     {
-                                      // fill the fields of the
+                                       // fill the fields of the
                                       // exception object
-      e.set_fields (file, line, function, cond, exc_name);
+       e.set_fields (file, line, function, cond, exc_name);
       
                                       // if no other exception has
                                       // been displayed before, show
                                       // this one
       if (n_treated_exceptions == 0)
        {
-         std::cerr << "--------------------------------------------------------"
+          std::cerr << "--------------------------------------------------------"
                    << std::endl;
                                           // print out general data
          e.print_exc_data (std::cerr);
@@ -312,6 +318,7 @@ namespace deal_II_exceptions
                                       // increase number of treated
                                       // exceptions by one
       n_treated_exceptions++;
+      last_exception = &e;
     
     
                                       // abort the program now since
@@ -334,15 +341,16 @@ namespace deal_II_exceptions
            std::cerr << "******** Program is not aborted since another exception is active! ********"
                      << std::endl;
        }
-      else
-       std::abort ();
+      else if(deal_II_exceptions::abort_on_exception == true)
+         std::abort ();
     }
 
 
 
     void abort ()
     {
-      std::abort ();
+      if (deal_II_exceptions::abort_on_exception == true)
+         std::abort ();
     }
     
   }
@@ -370,8 +378,8 @@ namespace
 {
   struct preload_terminate_dummy
   {
-      preload_terminate_dummy()
-        { std::set_terminate (__gnu_cxx::__verbose_terminate_handler); }
+     preload_terminate_dummy()
+       { std::set_terminate(__gnu_cxx::__verbose_terminate_handler); }
   };
 
   static preload_terminate_dummy dummy;
index de8f9a1246a7d9712e87d4a00c3eae40f0bc6d2e..1cb38541514e4c82adbbb3518a7cf80de3960be9 100644 (file)
@@ -240,7 +240,16 @@ inconvenience this causes.
 <a name="base"></a>
 <h3>base</h3>
 
-<ol>  
+<ol>
+  <li> <p>
+       New: A function <code class="member">
+       deal_II_exceptions::disable_abort_on_exception</code> now allows
+       to disable program abortion when an assertion fails. This is used
+       in regression tests.
+       <br>
+       (Ralf B. Schulz, 2005/07/13)
+       </p>
+       
   <li> <p>
        Improved: The <code class="class">QProjector</code> has functions
        <code class="class">project_to_face</code> and

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.