From: wolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Date: Wed, 9 Jan 2002 16:51:27 +0000 (+0000)
Subject: Further improve the working of the exception mechanism.
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96f0786ff0a5ad05f92c5994d19bcc51fc644c05;p=dealii-svn.git

Further improve the working of the exception mechanism.


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

diff --git a/deal.II/base/include/base/exceptions.h b/deal.II/base/include/base/exceptions.h
index e0c21fbc88..3fade7e8f5 100644
--- a/deal.II/base/include/base/exceptions.h
+++ b/deal.II/base/include/base/exceptions.h
@@ -180,6 +180,12 @@
  *  not terminate the program to allow that the thrown exception
  *  propagates to some place where its message can be displayed.
  *
+ *  Since it is common that one failed assertion leads to a whole
+ *  chain of others, we only ever print the very first message. If the
+ *  program is then aborted, that is no problem. If it is not (since a
+ *  C++ exception is active), only the first is displayed and a
+ *  message about suppressed follow-up messages is shown.
+ *
  *
  *  @sect2{Use of run-time exceptions}
  *
@@ -394,6 +400,28 @@ class ExceptionBase : public std::exception
 				      * Name of the exception and call sequence.
 				      */
     const char  *exc;
+
+				     /**
+				      * Number of exceptions dealt
+				      * with so far. Zero at program
+				      * start. Messages are only
+				      * displayed if the value is
+				      * zero.
+				      */
+    static unsigned int n_treated_exceptions;
+
+				     /**
+				      * Make this function a friend
+				      * since it needs access to the
+				      * @p{n_treated_exceptions}
+				      * variable.
+				      */
+    template <class exc> friend void __IssueError_Assert (const char *file,
+							  int         line,
+							  const char *function,
+							  const char *cond,
+							  const char *exc_name,
+							  exc         e);
 };
 
 
@@ -413,16 +441,37 @@ void __IssueError_Assert (const char *file,
 			  const char *exc_name,
 			  exc         e)
 {
-				   // Fill the fields of the exception object
+				   // fill the fields of the exception object
   e.SetFields (file, line, function, cond, exc_name);
-  std::cerr << "--------------------------------------------------------"
-	    << std::endl;
-				   // print out general data
-  e.PrintExcData (std::cerr);
-				   // print out exception specific data
-  e.PrintInfo (std::cerr);
-  std::cerr << "--------------------------------------------------------"
-	    << std::endl;
+
+				   // if no other exception has been
+				   // displayed before, show this one
+  if (ExceptionBase::n_treated_exceptions == 0)
+    {
+      std::cerr << "--------------------------------------------------------"
+		<< std::endl;
+				       // print out general data
+      e.PrintExcData (std::cerr);
+				       // print out exception specific data
+      e.PrintInfo (std::cerr);
+      std::cerr << "--------------------------------------------------------"
+		<< std::endl;
+    }
+  else
+    {
+				       // if this is the first
+				       // follow-up message, display a
+				       // message that further
+				       // exceptions are suppressed
+      if (ExceptionBase::n_treated_exceptions == 1)
+	std::cerr << "******** More assertions fail but messages are suppressed! ********"
+		  << std::endl;
+    };
+
+				   // increase number of treated
+				   // exceptions by one
+  ExceptionBase::n_treated_exceptions++;
+      
 
 				   // abort the program now since
 				   // something has gone horribly
@@ -435,7 +484,7 @@ void __IssueError_Assert (const char *file,
 				   // see the original exception. in
 				   // that case indicate that the
 				   // program is not aborted due to
-				   // this reason
+				   // this reason.
   if (std::uncaught_exception() == true)
     std::cerr << "******** Program is not aborted since another exception is active! ********"
 	      << std::endl;
diff --git a/deal.II/base/source/exceptions.cc b/deal.II/base/source/exceptions.cc
index 0f8eca90a2..18e293694f 100644
--- a/deal.II/base/source/exceptions.cc
+++ b/deal.II/base/source/exceptions.cc
@@ -25,6 +25,9 @@
 #endif
 
 
+unsigned int ExceptionBase::n_treated_exceptions;
+
+
 ExceptionBase::ExceptionBase () :
 		file(""), line(0), function(""), cond(""), exc("")
 {};