]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid exceptions without message. 5316/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 24 Oct 2017 00:21:04 +0000 (18:21 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 24 Oct 2017 23:58:14 +0000 (17:58 -0600)
include/deal.II/dofs/dof_accessor.templates.h
include/deal.II/grid/tria_accessor.h
include/deal.II/grid/tria_accessor.templates.h
include/deal.II/grid/tria_iterator.h

index 6ea92e3228c5a1eb0f17b30f43b20bf0b8e40446..ade4e1ac8dff926ea8d0b8cb251e9651467521a7 100644 (file)
@@ -3344,7 +3344,7 @@ DoFCellAccessor<DoFHandlerType,level_dof_access>::neighbor (const unsigned int i
 
 #ifdef DEBUG
   if (q.state() != IteratorState::past_the_end)
-    Assert (q->used(), TriaAccessorExceptions::ExcUnusedCellAsNeighbor());
+    Assert (q->used(), ExcInternalError());
 #endif
   return q;
 }
@@ -3363,7 +3363,7 @@ DoFCellAccessor<DoFHandlerType,level_dof_access>::child (const unsigned int i) c
 
 #ifdef DEBUG
   if (q.state() != IteratorState::past_the_end)
-    Assert (q->used(), TriaAccessorExceptions::ExcUnusedCellAsChild());
+    Assert (q->used(), ExcInternalError());
 #endif
   return q;
 }
index 4e7883b149b94fba78812b70b654c3ab0d377301..22e9fd1aba559883567cede7b368bdbc3abb400a 100644 (file)
@@ -124,11 +124,20 @@ template <int spacedim>                         class TriaAccessor<0, 1, spacedi
  */
 namespace TriaAccessorExceptions
 {
-//TODO: Write documentation!
   /**
    * @ingroup Exceptions
    */
-  DeclException0 (ExcCellNotUsed);
+  DeclExceptionMsg (ExcCellNotUsed,
+                    "The operation you are attempting can only be performed for "
+                    "(cell, face, or edge) iterators that point to valid "
+                    "objects. These objects need not necessarily be active, "
+                    "i.e., have no children, but they need to be part of a "
+                    "triangulation. (The objects pointed to by an iterator "
+                    "may -- after coarsening -- also be objects that used "
+                    "to be part of a triangulation, but are now no longer "
+                    "used. Their memory location may have been retained "
+                    "for re-use upon the next mesh refinement, but is "
+                    "currently unused.)");
   /**
    * The cell is not an
    * @ref GlossActive "active"
@@ -138,54 +147,64 @@ namespace TriaAccessorExceptions
    *
    * @ingroup Exceptions
    */
-  DeclException0 (ExcCellNotActive);
+  DeclExceptionMsg (ExcCellNotActive,
+                    "The operation you are attempting can only be performed for "
+                    "(cell, face, or edge) iterators that point to 'active' "
+                    "objects. 'Active' objects are those that do not have "
+                    "children (in the case of cells), or that are part of "
+                    "an active cell (in the case of faces or edges). However, "
+                    "the object on which you are trying the current "
+                    "operation is not 'active' in this sense.");
   /**
    * Trying to access the children of a cell which is in fact active.
    *
    * @ingroup Exceptions
    */
-  DeclException0 (ExcCellHasNoChildren);
+  DeclExceptionMsg (ExcCellHasNoChildren,
+                    "The operation you are attempting can only be performed for "
+                    "(cell, face, or edge) iterators that have children, "
+                    "but the object on which you are trying the current "
+                    "operation does not have any.");
   /**
    * Trying to access the parent of a cell which is in the coarsest level of
    * the triangulation.
    *
    * @ingroup Exceptions
    */
-  DeclException0 (ExcCellHasNoParent);
-//TODO: Write documentation!
-  /**
-   * @ingroup Exceptions
-   */
-  DeclException0 (ExcUnusedCellAsChild);
-//TODO: Write documentation!
+  DeclExceptionMsg (ExcCellHasNoParent,
+                    "The operation you are attempting can only be performed for "
+                    "(cell, face, or edge) iterators that have a parent object, "
+                    "but the object on which you are trying the current "
+                    "operation does not have one -- i.e., it is on the "
+                    "coarsest level of the triangulation.");
   /**
    * @ingroup Exceptions
    */
   DeclException1 (ExcCantSetChildren,
                   int,
-                  << "You can only set the child index if the cell has no "
-                  << "children, or clear it. The given "
-                  << "index was " << arg1 << " (-1 means: clear children)");
-//TODO: Write documentation!
-  /**
-   * @ingroup Exceptions
-   */
-  DeclException0 (ExcUnusedCellAsNeighbor);
-//TODO: Write documentation!
-  /**
-   * @ingroup Exceptions
-   */
-  DeclException0 (ExcUncaughtCase);
-//TODO: Write documentation!
+                  << "You can only set the child index if the cell does not "
+                  << "currently have children registered; or you can clear it. "
+                  << "The given index was " << arg1 << " (-1 means: clear children).");
   /**
    * @ingroup Exceptions
    */
-  DeclException0 (ExcDereferenceInvalidObject);
-//TODO: Write documentation!
+  template <typename AccessorType>
+  DeclException1 (ExcDereferenceInvalidObject,
+                  AccessorType,
+                  << "You tried to dereference an iterator for which this "
+                  << "is not possible. More information on this iterator: "
+                  << "index=" << arg1.index()
+                  << ", state="
+                  << (arg1.state() == IteratorState::valid ? "valid" :
+                      (arg1.state() == IteratorState::past_the_end ?
+                       "past_the_end" : "invalid")));
   /**
    * @ingroup Exceptions
    */
-  DeclException0 (ExcCantCompareIterators);
+  DeclExceptionMsg (ExcCantCompareIterators,
+                    "Iterators can only be compared if they point to the same "
+                    "triangulation, or if neither of them are associated "
+                    "with a triangulation.");
 //TODO: Write documentation!
   /**
    * @ingroup Exceptions
index 23280bb6cf4933afc85af1555080440933c3ae64..48f187b00cb51c485e7258edae6bbd014ddc86e6 100644 (file)
@@ -1215,7 +1215,7 @@ bool
 TriaAccessor<structdim,dim,spacedim>::used () const
 {
   Assert (this->state() == IteratorState::valid,
-          TriaAccessorExceptions::ExcDereferenceInvalidObject());
+          TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(*this));
   return this->objects().used[this->present_index];
 }
 
@@ -1409,7 +1409,7 @@ template <int structdim, int dim, int spacedim>
 void TriaAccessor<structdim, dim, spacedim>::set_used_flag () const
 {
   Assert (this->state() == IteratorState::valid,
-          TriaAccessorExceptions::ExcDereferenceInvalidObject());
+          TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(*this));
   this->objects().used[this->present_index] = true;
 }
 
@@ -1420,7 +1420,7 @@ void
 TriaAccessor<structdim, dim, spacedim>::clear_used_flag () const
 {
   Assert (this->state() == IteratorState::valid,
-          TriaAccessorExceptions::ExcDereferenceInvalidObject());
+          TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(*this));
   this->objects().used[this->present_index] = false;
 }
 
@@ -1492,7 +1492,7 @@ RefinementCase<structdim>
 TriaAccessor<structdim, dim, spacedim>::refinement_case() const
 {
   Assert (this->state() == IteratorState::valid,
-          TriaAccessorExceptions::ExcDereferenceInvalidObject());
+          TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(*this));
 
   switch (structdim)
     {
@@ -1541,7 +1541,7 @@ TriaAccessor<structdim,dim,spacedim>::child (const unsigned int i) const
      child_index (i));
 
   Assert ((q.state() == IteratorState::past_the_end) || q->used(),
-          TriaAccessorExceptions::ExcUnusedCellAsChild());
+          ExcInternalError());
 
   return q;
 }
@@ -1602,7 +1602,7 @@ bool
 TriaAccessor<structdim,dim,spacedim>::has_children () const
 {
   Assert (this->state() == IteratorState::valid,
-          TriaAccessorExceptions::ExcDereferenceInvalidObject());
+          TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(*this));
 
   // each set of two children are stored
   // consecutively, so we only have to find
@@ -1631,7 +1631,7 @@ TriaAccessor<structdim, dim, spacedim>::
 set_refinement_case (const RefinementCase<structdim> &refinement_case) const
 {
   Assert (this->state() == IteratorState::valid,
-          TriaAccessorExceptions::ExcDereferenceInvalidObject());
+          TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(*this));
   Assert (static_cast<unsigned int> (this->present_index) <
           this->objects().refinement_cases.size(),
           ExcIndexRange(this->present_index, 0,
@@ -1647,7 +1647,7 @@ void
 TriaAccessor<structdim, dim, spacedim>::clear_refinement_case () const
 {
   Assert (this->state() == IteratorState::valid,
-          TriaAccessorExceptions::ExcDereferenceInvalidObject());
+          TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(*this));
   Assert (static_cast<unsigned int> (this->present_index) <
           this->objects().refinement_cases.size(),
           ExcIndexRange(this->present_index, 0,
@@ -1674,11 +1674,20 @@ TriaAccessor<structdim, dim, spacedim>::set_children (const unsigned int i,
   // the location of the set of children
   const unsigned int n_sets_of_two = GeometryInfo<structdim>::max_children_per_cell/2;
 
-  Assert ((index==-1) ||
-          (i==0 && !this->has_children() && (index>=0)) ||
-          (i>0  &&  this->has_children() && (index>=0) &&
-           this->objects().children[n_sets_of_two*this->present_index+i/2] == -1),
-          TriaAccessorExceptions::ExcCantSetChildren(index));
+  Assert (
+    // clearing the child index for a cell
+    (index==-1)
+    ||
+    // if setting the child index for the i'th child (with i==0),
+    // then the index must be a non-negative number
+    (i==0 && !this->has_children() && (index>=0))
+    ||
+    // if setting the child index for the i'th child (with i>0),
+    // then the previously stored index must be the invalid
+    // index
+    (i>0  &&  this->has_children() && (index>=0) &&
+     this->objects().children[n_sets_of_two*this->present_index+i/2] == -1),
+    TriaAccessorExceptions::ExcCantSetChildren(index));
 
   this->objects().children[n_sets_of_two*this->present_index+i/2] = index;
 }
@@ -3552,7 +3561,7 @@ CellAccessor<dim,spacedim>::neighbor (const unsigned int i) const
   q (this->tria, neighbor_level (i), neighbor_index (i));
 
   Assert ((q.state() == IteratorState::past_the_end) || q->used(),
-          TriaAccessorExceptions::ExcUnusedCellAsNeighbor());
+          ExcInternalError());
 
   return q;
 }
@@ -3568,7 +3577,7 @@ CellAccessor<dim,spacedim>::child (const unsigned int i) const
   q (this->tria, this->present_level+1, this->child_index (i));
 
   Assert ((q.state() == IteratorState::past_the_end) || q->used(),
-          TriaAccessorExceptions::ExcUnusedCellAsChild());
+          ExcInternalError());
 
   return q;
 }
index a0826487f55a24015e82f3e39cd960dbe16f32fd..67aea98b7715b1d303de7bec7e75ec90c5e69e2e 100644 (file)
@@ -482,8 +482,7 @@ public:
                        "past_the_end" : "invalid")));
 
   /**
-   * Exception for lower-dimensional TriaObjects without level, i.e. objects
-   * faces are constructed with.
+   * Exception.
    */
   DeclException1 (ExcDereferenceInvalidObject,
                   Accessor,

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.