]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use C++ exception handling to guard in/out operations. Consistency and parameter...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 14 Aug 1998 14:23:53 +0000 (14:23 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 14 Aug 1998 14:23:53 +0000 (14:23 +0000)
git-svn-id: https://svn.dealii.org/trunk@486 0785d39b-7218-0410-832d-ea1e28bc413d

12 files changed:
deal.II/base/include/base/exceptions.h
deal.II/base/source/parameter_handler.cc
deal.II/deal.II/Conventions
deal.II/deal.II/Todo
deal.II/deal.II/include/grid/point.h
deal.II/deal.II/source/dofs/dof_constraints.cc
deal.II/deal.II/source/grid/tria.cc
deal.II/deal.II/source/numerics/data_io.cc
deal.II/lac/source/Makefile
deal.II/lac/source/dfmatrix.cc
deal.II/lac/source/dsmatrix.cc
deal.II/lac/source/dvector.cc

index 7599134993e4f96313cfca65aacc5139b99b7cf9..f0161654c074457172f6998fe816776e6cd7f2cc 100644 (file)
@@ -423,6 +423,24 @@ class Exception5 : public ExceptionBase {                             \
 
 
 
+/* ----------------------- Declare some global exceptions which are
+                           not generated by the Assert mechanism, but
+                          are rather used for the throw and catch
+                          way.
+*/
+
+#include <exception>
+
+class GlobalExcIO : public exception {
+  public:
+    virtual const char * what () const {
+      return __PRETTY_FUNCTION__;
+    };
+};
+
+    
+
+
 /*----------------------------   exceptions.h     ---------------------------*/
 /* end of #ifndef __exceptions_H */
 #endif
index 2ac99bae69edbff27e5a6a19bf2e40c6ed22760a..8758a728b8d5c6a767eb9a05e590b0518e3a2eee 100644 (file)
@@ -117,6 +117,9 @@ ParameterHandler::~ParameterHandler () {};
 
 
 bool ParameterHandler::read_input (istream &input) {
+  if (!input)
+    throw GlobalExcIO ();
+
   string line;
   int lineno=0;
   while (input) 
@@ -333,6 +336,9 @@ ostream & ParameterHandler::print_parameters (ostream &out, OutputStyle style) {
                                   // given as "style"
   Assert ((style == Text) || (style == LaTeX), ExcNotImplemented());
 
+  if (!out)
+    throw GlobalExcIO ();
+
   switch (style) 
     {
       case Text:
@@ -374,7 +380,10 @@ void ParameterHandler::print_parameters_section (ostream &out,
                                   // assert that only known formats are
                                   // given as "style"
   Assert ((style == Text) || (style == LaTeX), ExcNotImplemented());
-  
+
+  if (!out)
+    throw GlobalExcIO ();
+
   Section *pd = get_present_defaults_subsection ();
   Section *pc = get_present_changed_subsection ();
 
@@ -694,12 +703,16 @@ MultipleParameterLoop::~MultipleParameterLoop () {};
 
 
 bool MultipleParameterLoop::read_input (istream &input) {
+  if (!input)
+    throw GlobalExcIO ();
+
   bool x = ParameterHandler::read_input (input);
   if (x) init_branches ();
   return x;
 };
 
 
+
 bool MultipleParameterLoop::read_input (const string &filename) {
                                   // I don't know why it is necessary to
                                   // declare this function: simply not
@@ -717,6 +730,7 @@ bool MultipleParameterLoop::read_input (const string &filename) {
 };
 
 
+
 bool MultipleParameterLoop::read_input_from_string (const char *s) {
   bool x = ParameterHandler::read_input (s);
   init_branches ();
index eb6228ec654c4f58e94a276ca87f2ef024da3613..5b38a2b2ee8a6d2ba45e3199a91f6e9d2035c8d7 100644 (file)
@@ -55,5 +55,11 @@ Here are some conventions for source code of the deal.II library:
   input parameters shall precede the output parameters, unless there
   are good reasons to change this order.
 
-11./ Each class has to have at least 200 pages of documentation ;-)
+11./ Exceptions are used for internal parameter checking and for
+  consistency checks through the Assert macro. Exception handling
+  like done by the C++ language (try/throw/catch) are used to
+  handle run time errors (like I/O failures) which must be on
+  in any case, not only in debug mode.
+
+12./ Each class has to have at least 200 pages of documentation ;-)
 
index 43a413357fa79ab0c8aece51e4575747823cfb0e..2a15993ef3e2ec28134e62767fe7df5ee1d3d723 100644 (file)
@@ -128,6 +128,11 @@ Remove the workaround with the BoundaryHelper class which was
   (previous ones worked flawless)
 
 
+Check the pattern matching in the parameter handler module using
+  the C++ exception handling mechanism rather than Asserts, since
+  this should be on also when debug mode is off.
+
+
 
 
 
index 709fbf908568c3bdd0f1aba795d77d543d8eb2b6..999877ae461fcc9776e520aa6cdb1ef793667030 100644 (file)
@@ -397,6 +397,10 @@ ostream & operator << (ostream &out, const Point<dim> &p) {
   for (unsigned int i=0; i<dim-1; ++i)
     out << p(i) << ' ';
   out << p(dim-1);
+
+  if (!out)
+    throw GlobalExcIO ();
+
   return out;
 };
 
@@ -405,6 +409,10 @@ template <>
 inline
 ostream & operator << (ostream &out, const Point<1> &p) {
   out << p(0);
+
+  if (!out)
+    throw GlobalExcIO ();
+
   return out;
 };
   
index eeab1152af900e83b8e56e5faf484ed2bdbcbab2..aa91822b390faaaa9bf279a993988b45241f9c10 100644 (file)
@@ -703,4 +703,7 @@ void ConstraintMatrix::print (ostream &out) const {
       out << "    " << lines[i].line
          << " " << lines[i].entries[j].first
          << ":  " << lines[i].entries[j].second << endl;
+
+  if (!out)
+    throw GlobalExcIO ();
 };
index 57fe54ac1e6912ebde292215fae29253616938de..5b1675582a3b141e4f4974df2c6bc66683effa4d 100644 (file)
@@ -1903,10 +1903,16 @@ void Triangulation<dim>::print_gnuplot (ostream &out, const unsigned int level)
                               active_cell_iterator(end()) :
                               begin_active (level+1));
 
+  if (!out)
+    throw GlobalExcIO ();
+
   out << "#Active cells on level " << level
       << ": " << n_active_cells (level) << endl;
   for (; cell != endc; ++cell)
     print_gnuplot (out, cell);
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
 
@@ -1916,9 +1922,15 @@ void Triangulation<dim>::print_gnuplot (ostream &out, const unsigned int level)
 template <>
 void Triangulation<1>::print_gnuplot (ostream &out,
                                      const active_cell_iterator & cell) const {
+  if (!out)
+    throw GlobalExcIO ();
+
   out << cell->vertex(0) << " " << cell->level() << endl
       << cell->vertex(1) << " " << cell->level() << endl
       << endl;
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
 #endif
@@ -1929,6 +1941,9 @@ void Triangulation<1>::print_gnuplot (ostream &out,
 template <>
 void Triangulation<2>::print_gnuplot (ostream &out,
                                      const active_cell_iterator & cell) const {
+  if (!out)
+    throw GlobalExcIO ();
+
   out << cell->vertex(0) << " " << cell->level() << endl
       << cell->vertex(1) << " " << cell->level() << endl
       << cell->vertex(2) << " " << cell->level() << endl
@@ -1936,6 +1951,9 @@ void Triangulation<2>::print_gnuplot (ostream &out,
       << cell->vertex(0) << " " << cell->level() << endl
       << endl  // double new line for gnuplot 3d plots
       << endl;
+
+  if (!out)
+    throw GlobalExcIO ();  
 };
 
 #endif
@@ -3512,6 +3530,9 @@ void Triangulation<dim>::write_bool_vector (const unsigned int  magic_number1,
   for (unsigned int position=0; position<N; ++position)
     flags[position/8] |= (v[position] ? (1<<(position%8)) : 0);
 
+  if (!out)
+    throw GlobalExcIO ();
+
                                   // format:
                                   // 0. magic number
                                   // 1. number of flags
@@ -3522,8 +3543,11 @@ void Triangulation<dim>::write_bool_vector (const unsigned int  magic_number1,
     out << static_cast<unsigned int>(flags[i]) << " ";
   
   out << endl << magic_number2 << endl;
-
+  
   delete[] flags;
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
 
@@ -3533,6 +3557,9 @@ void Triangulation<dim>::read_bool_vector (const unsigned int  magic_number1,
                                           vector<bool>       &v,
                                           const unsigned int  magic_number2,
                                           istream            &in) {
+  if (!in)
+    throw GlobalExcIO ();
+
   unsigned int magic_number;
   in >> magic_number;
   Assert (magic_number==magic_number1, ExcGridReadError());
@@ -3556,6 +3583,9 @@ void Triangulation<dim>::read_bool_vector (const unsigned int  magic_number1,
   Assert (magic_number==magic_number2, ExcGridReadError());
 
   delete[] flags;
+
+  if (!in)
+    throw GlobalExcIO ();
 };
 
 
index cbb170589048be8c46a8c6d100b1d243959f33d4..4e43f7f324a32147b18bdcec6787e76e80a26dd8 100644 (file)
@@ -51,6 +51,8 @@ void DataIn<dim>::read_ucd (istream &in) {
   Assert (tria != 0, ExcNoTriangulationSelected());
   Assert ((1<=dim) && (dim<=2), ExcNotImplemented());
 
+  if (!in)
+    throw GlobalExcIO ();
 
                                   // skip comments at start of file
   char c;
@@ -170,7 +172,10 @@ void DataIn<dim>::read_ucd (istream &in) {
 
                                   // check that no forbidden arrays are used
   Assert (subcelldata.check_consistency(dim), ExcInternalError());
-  
+
+  if (!in)
+    throw GlobalExcIO ();
+
   tria->create_triangulation (vertices, cells, subcelldata);
 };
 
@@ -237,7 +242,7 @@ void DataOut<dim>::write_ucd (ostream &out) const {
   
   DoFHandler<dim>::active_cell_iterator cell,
                                        endc = dofs->end();
-  unsigned int n_vertex_dofs;
+  unsigned int n_vertex_dofs = 0;
 
                                   // first loop over all cells to
                                   // find out how many degrees of
@@ -254,7 +259,6 @@ void DataOut<dim>::write_ucd (ostream &out) const {
             ++vertex) 
          is_vertex_dof[cell->vertex_dof_index(vertex,0)] = true;
 
-      n_vertex_dofs = 0;
       for (unsigned i=0; i!=is_vertex_dof.size(); ++i)
        if (is_vertex_dof[i] == true)
          ++n_vertex_dofs;
@@ -384,6 +388,9 @@ void DataOut<dim>::write_ucd (ostream &out) const {
     };
                                   // no cell data
                                   // no model data
+  if (!out)
+    throw GlobalExcIO ();
+
 };
 
 
@@ -453,6 +460,9 @@ void DataOut<dim>::write_ucd_faces (ostream &out,
 
        ++index;
       };         
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
       
@@ -562,6 +572,9 @@ void DataOut<dim>::write_gnuplot (ostream &out) const {
                Assert (false, ExcNotImplemented());
        };
     };
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
 
@@ -655,6 +668,9 @@ void DataOut<2>::write_povray (ostream &out) const {
          << endl;
     };
   out << "}";     
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
       
index 04a727f52ab12845deb559ab1f5a10aba084a0e8..3efa428fb41cc3e874ecb84bb0c497fe57ad5c06 100644 (file)
@@ -3,7 +3,7 @@
 CXX       = c++
 INCLUDE   = -I../include -I../../base/include
 CXXFLAGS.g= -DDEBUG -g -Wall -W -pedantic -Wconversion \
-            -Winline -Woverloaded-virtual -fno-rtti -fno-exceptions \
+            -Winline -Woverloaded-virtual -fno-rtti \
             $(INCLUDE)
 CXXFLAGS  =-O3 -Wuninitialized -finline-functions -ffast-math \
            -funroll-loops -felide-constructors -fnonnull-objects \
index 2b958387947416e47a15697b63362b72827cd63a..34b785541abdacc202835cf2ab164090ff0f4b53 100644 (file)
@@ -1102,5 +1102,8 @@ void dFMatrix::print_formatted (ostream &out, const unsigned int precision) cons
       out << endl;
     };
 
+  if (!out)
+    throw GlobalExcIO ();
+
   out.setf (0, ios::floatfield);                 // reset output format
 };
index 51097ecf5ed7389856a2867d9a5a49af1181657b..d6dcce0e3dc50f8743543016780f4c9a52f0377a 100644 (file)
@@ -327,6 +327,9 @@ dSMatrixStruct::print_gnuplot (ostream &out) const
     for (unsigned int j=rowstart[i]; j<rowstart[i+1]; ++j)
       if (colnums[j]>=0)
        out << i << " " << -colnums[j] << endl;
+
+  if (!out)
+    throw GlobalExcIO ();
 }
 
 
@@ -748,6 +751,9 @@ void dSMatrix::print (ostream &out) const {
   for (unsigned int i=0; i<cols->rows; ++i)
     for (unsigned int j=cols->rowstart[i]; j<cols->rowstart[i+1]; ++j)
       out << "(" << i << "," << cols->colnums[j] << ") " << val[j] << endl;
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
 
@@ -768,6 +774,8 @@ void dSMatrix::print_formatted (ostream &out, const unsigned int precision) cons
          out << setw(precision+8) << " ";
       out << endl;
     };
+  if (!out)
+    throw GlobalExcIO ();
 
   out.setf (0, ios::floatfield);                 // reset output format
 };
index 9a40eea7fb8f35eb71814e2f2b586a8d5e389cde..05febceda76b77cfbd747ce4453bc37952bfaacb 100644 (file)
@@ -609,6 +609,9 @@ void dVector::print (ostream &out) const {
   Assert (dim!=0, ExcEmptyVector());
   for (unsigned int i=0; i<size(); ++i)
     out << val[i] << endl;
+
+  if (!out)
+    throw GlobalExcIO ();
 };
 
 

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.