From: rschulz Date: Wed, 13 Jul 2005 22:02:07 +0000 (+0000) Subject: added disable_abort_on_exception() function to prevent the Assert() macro X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e050546355b2b54bea7a6b3c288e232b3b197c83;p=dealii-svn.git added disable_abort_on_exception() function to prevent the Assert() macro 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 --- diff --git a/deal.II/base/include/base/exceptions.h b/deal.II/base/include/base/exceptions.h index b4f284a570..f0d04f011e 100644 --- a/deal.II/base/include/base/exceptions.h +++ b/deal.II/base/include/base/exceptions.h @@ -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 diff --git a/deal.II/base/source/exceptions.cc b/deal.II/base/source/exceptions.cc index 9ab3b9c7ef..71bae91229 100644 --- a/deal.II/base/source/exceptions.cc +++ b/deal.II/base/source/exceptions.cc @@ -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; diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index de8f9a1246..1cb3854151 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -240,7 +240,16 @@ inconvenience this causes.

base

-
    +
      +
    1. + New: A function + deal_II_exceptions::disable_abort_on_exception now allows + to disable program abortion when an assertion fails. This is used + in regression tests. +
      + (Ralf B. Schulz, 2005/07/13) +

      +
    2. Improved: The QProjector has functions project_to_face and