From: Wolfgang Bangerth Date: Tue, 24 Oct 2017 00:21:04 +0000 (-0600) Subject: Avoid exceptions without message. X-Git-Tag: v9.0.0-rc1~886^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F5316%2Fhead;p=dealii.git Avoid exceptions without message. --- diff --git a/include/deal.II/dofs/dof_accessor.templates.h b/include/deal.II/dofs/dof_accessor.templates.h index 6ea92e3228..ade4e1ac8d 100644 --- a/include/deal.II/dofs/dof_accessor.templates.h +++ b/include/deal.II/dofs/dof_accessor.templates.h @@ -3344,7 +3344,7 @@ DoFCellAccessor::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::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; } diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index 4e7883b149..22e9fd1aba 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -124,11 +124,20 @@ template 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 + 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 diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 23280bb6cf..48f187b00c 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -1215,7 +1215,7 @@ bool TriaAccessor::used () const { Assert (this->state() == IteratorState::valid, - TriaAccessorExceptions::ExcDereferenceInvalidObject()); + TriaAccessorExceptions::ExcDereferenceInvalidObject(*this)); return this->objects().used[this->present_index]; } @@ -1409,7 +1409,7 @@ template void TriaAccessor::set_used_flag () const { Assert (this->state() == IteratorState::valid, - TriaAccessorExceptions::ExcDereferenceInvalidObject()); + TriaAccessorExceptions::ExcDereferenceInvalidObject(*this)); this->objects().used[this->present_index] = true; } @@ -1420,7 +1420,7 @@ void TriaAccessor::clear_used_flag () const { Assert (this->state() == IteratorState::valid, - TriaAccessorExceptions::ExcDereferenceInvalidObject()); + TriaAccessorExceptions::ExcDereferenceInvalidObject(*this)); this->objects().used[this->present_index] = false; } @@ -1492,7 +1492,7 @@ RefinementCase TriaAccessor::refinement_case() const { Assert (this->state() == IteratorState::valid, - TriaAccessorExceptions::ExcDereferenceInvalidObject()); + TriaAccessorExceptions::ExcDereferenceInvalidObject(*this)); switch (structdim) { @@ -1541,7 +1541,7 @@ TriaAccessor::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::has_children () const { Assert (this->state() == IteratorState::valid, - TriaAccessorExceptions::ExcDereferenceInvalidObject()); + TriaAccessorExceptions::ExcDereferenceInvalidObject(*this)); // each set of two children are stored // consecutively, so we only have to find @@ -1631,7 +1631,7 @@ TriaAccessor:: set_refinement_case (const RefinementCase &refinement_case) const { Assert (this->state() == IteratorState::valid, - TriaAccessorExceptions::ExcDereferenceInvalidObject()); + TriaAccessorExceptions::ExcDereferenceInvalidObject(*this)); Assert (static_cast (this->present_index) < this->objects().refinement_cases.size(), ExcIndexRange(this->present_index, 0, @@ -1647,7 +1647,7 @@ void TriaAccessor::clear_refinement_case () const { Assert (this->state() == IteratorState::valid, - TriaAccessorExceptions::ExcDereferenceInvalidObject()); + TriaAccessorExceptions::ExcDereferenceInvalidObject(*this)); Assert (static_cast (this->present_index) < this->objects().refinement_cases.size(), ExcIndexRange(this->present_index, 0, @@ -1674,11 +1674,20 @@ TriaAccessor::set_children (const unsigned int i, // the location of the set of children const unsigned int n_sets_of_two = GeometryInfo::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::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::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; } diff --git a/include/deal.II/grid/tria_iterator.h b/include/deal.II/grid/tria_iterator.h index a0826487f5..67aea98b77 100644 --- a/include/deal.II/grid/tria_iterator.h +++ b/include/deal.II/grid/tria_iterator.h @@ -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,