13#ifndef dealii_exceptions_h
14#define dealii_exceptions_h
23#include <Kokkos_Macros.hpp>
24#if DEAL_II_KOKKOS_VERSION_GTE(4, 2, 0)
25# include <Kokkos_Abort.hpp>
27# include <Kokkos_Core.hpp>
90 const
char *exc_name);
97 what() const noexcept override;
157#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
201 "A piece of code is attempting a division by zero. This is "
202 "likely going to lead to results that make no sense.");
211 template <
typename Number>
215 <<
"In a significant number of places, deal.II checks that some intermediate "
216 <<
"value is a finite number (as opposed to plus or minus infinity, or "
217 <<
"NaN/Not a Number). In the current function, we encountered a number "
218 <<
"that is not finite (its value is " << arg1 <<
" and therefore "
219 <<
"violates the current assertion).\n\n"
220 <<
"This may be due to the fact that some operation in this function "
221 <<
"created such a value, or because one of the arguments you passed "
222 <<
"to the function already had this value from some previous "
223 <<
"operation. In the latter case, this function only triggered the "
224 <<
"error but may not actually be responsible for the computation of "
225 <<
"the number that is not finite.\n\n"
226 <<
"There are two common cases where this situation happens. First, your "
227 <<
"code (or something in deal.II) divides by zero in a place where this "
228 <<
"should not happen. Or, you are trying to solve a linear system "
229 <<
"with an unsuitable solver (such as an indefinite or non-symmetric "
230 <<
"linear system using a Conjugate Gradient solver); such attempts "
231 <<
"oftentimes yield an operation somewhere that tries to divide "
232 <<
"by zero or take the square root of a negative value.\n\n"
233 <<
"In any case, when trying to find the source of the error, "
234 <<
"recall that the location where you are getting this error is "
235 <<
"simply the first place in the program where there is a check "
236 <<
"that a number (e.g., an element of a solution vector) is in fact "
237 <<
"finite, but that the actual error that computed the number "
238 <<
"may have happened far earlier. To find this location, you "
239 <<
"may want to add checks for finiteness in places of your "
240 <<
"program visited before the place where this error is produced. "
241 <<
"One way to check for finiteness is to use the 'AssertIsFinite' "
249 "Your program tried to allocate some memory but this "
250 "allocation failed. Typically, this either means that "
251 "you simply do not have enough memory in your system, "
252 "or that you are (erroneously) trying to allocate "
253 "a chunk of memory that is simply beyond all reasonable "
254 "size, for example because the size of the object has "
255 "been computed incorrectly."
257 "In the current case, the request was for "
258 << arg1 <<
" bytes.");
266 <<
"Destroying memory handler while " << arg1
267 <<
" objects are still allocated.");
273 "An input/output error has occurred. There are a number of "
274 "reasons why this may be happening, both for reading and "
275 "writing operations."
277 "If this happens during an operation that tries to read "
278 "data: First, you may be "
279 "trying to read from a file that doesn't exist or that is "
280 "not readable given its file permissions. Second, deal.II "
281 "uses this error at times if it tries to "
282 "read information from a file but where the information "
283 "in the file does not correspond to the expected format. "
284 "An example would be a truncated file, or a mesh file "
285 "that contains not only sections that describe the "
286 "vertices and cells, but also sections for additional "
287 "data that deal.II does not understand."
289 "If this happens during an operation that tries to write "
290 "data: you may be trying to write to a file to which file "
291 "or directory permissions do not allow you to write. A "
292 "typical example is where you specify an output file in "
293 "a directory that does not exist.");
303 <<
"Could not open file " << arg1
306 "If this happens during an operation that tries to read "
308 "trying to read from a file that doesn't exist or that is "
309 "not readable given its file permissions."
311 "If this happens during an operation that tries to write "
312 "data: you may be trying to write to a file to which file "
313 "or directory permissions do not allow you to write. A "
314 "typical example is where you specify an output file in "
315 "a directory that does not exist.");
326 "You are trying to use functionality in deal.II that is "
327 "currently not implemented. In many cases, this indicates "
328 "that there simply didn't appear much of a need for it, or "
329 "that the author of the original code did not have the "
330 "time to implement a particular case. If you hit this "
331 "exception, it is therefore worth the time to look into "
332 "the code to find out whether you may be able to "
333 "implement the missing functionality. If you do, please "
334 "consider providing a patch to the deal.II development "
335 "sources (see the deal.II website on how to contribute).");
358 "This exception -- which is used in many places in the "
359 "library -- usually indicates that some condition which "
360 "the author of the code thought must be satisfied at a "
361 "certain point in an algorithm, is not fulfilled. An "
362 "example would be that the first part of an algorithm "
363 "sorts elements of an array in ascending order, and "
364 "a second part of the algorithm later encounters an "
365 "element that is not larger than the previous one."
367 "There is usually not very much you can do if you "
368 "encounter such an exception since it indicates an error "
369 "in deal.II, not in your own program. Try to come up with "
370 "the smallest possible program that still demonstrates "
371 "the error and contact the deal.II mailing lists with it "
382 "You (or a place in the library) are trying to call a "
383 "function that is declared as a virtual function in a "
384 "base class but that has not been overridden in your "
387 "This exception happens in cases where the base class "
388 "cannot provide a useful default implementation for "
389 "the virtual function, but where we also do not want "
390 "to mark the function as abstract (i.e., with '=0' at the end) "
391 "because the function is not essential to the class in many "
392 "contexts. In cases like this, the base class provides "
393 "a dummy implementation that makes the compiler happy, but "
394 "that then throws the current exception."
396 "A concrete example would be the 'Function' class. It declares "
397 "the existence of 'value()' and 'gradient()' member functions, "
398 "and both are marked as 'virtual'. Derived classes have to "
399 "override these functions for the values and gradients of a "
400 "particular function. On the other hand, not every function "
401 "has a gradient, and even for those that do, not every program "
402 "actually needs to evaluate it. Consequently, there is no "
403 "*requirement* that a derived class actually override the "
404 "'gradient()' function (as there would be had it been marked "
405 "as abstract). But, since the base class cannot know how to "
406 "compute the gradient, if a derived class does not override "
407 "the 'gradient()' function and it is called anyway, then the "
408 "default implementation in the base class will simply throw "
411 "The exception you see is what happens in cases such as the "
412 "one just illustrated. To fix the problem, you need to "
413 "investigate whether the function being called should indeed have "
414 "been called; if the answer is 'yes', then you need to "
415 "implement the missing override in your class.");
422 <<
"Please provide an implementation for the function \""
432 <<
"The function \"" << arg1 <<
"\" returned the nonzero value " << arg2
433 <<
", but the calling site expected the return value to be zero. "
434 "This error often happens when the function in question is a 'callback', "
435 "that is a user-provided function called from somewhere within deal.II "
436 "or within an external library such as PETSc, Trilinos, SUNDIALS, etc., "
437 "that expect these callbacks to indicate errors via nonzero return "
458 <<
"You are trying to execute functionality that is "
459 <<
"impossible in " << arg1
460 <<
"d or simply does not make any sense.");
472 <<
"You are trying to execute functionality that is "
473 <<
"impossible in dimensions <" << arg1 <<
',' << arg2
474 <<
"> or simply does not make any sense.");
481 "In a check in the code, deal.II encountered a zero in "
482 "a place where this does not make sense. See the condition "
483 "that was being checked and that is printed further up "
484 "in the error message to get more information on what "
485 "the erroneous zero corresponds to.");
492 "The object you are trying to access is empty but it makes "
493 "no sense to attempt the operation you are trying on an "
506 <<
"Two sizes or dimensions were supposed to be equal, "
507 <<
"but aren't. They are " << arg1 <<
" and " << arg2 <<
'.');
517 <<
"Two integers should be equal to each other after a type conversion but "
518 <<
"aren't. A typical cause of this problem is that the integral types "
519 <<
"used by deal.II and an external library are different (e.g., one uses "
520 <<
"32-bit integers and the other uses 64-bit integers). The integers are "
521 << arg1 <<
" and " << arg2 <<
'.');
531 <<
"The size or dimension of one object, " << arg1
532 <<
" was supposed to be "
533 <<
"equal to one of two values, but isn't. The two possible "
534 <<
"values are " << arg2 <<
" and " << arg3 <<
'.');
553 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
','
556 " In the current case, this half-open range is in fact empty, "
557 "suggesting that you are accessing an element of an empty "
558 "collection such as a vector that has not been set to the "
577 template <
typename T>
583 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
','
586 " In the current case, this half-open range is in fact empty, "
587 "suggesting that you are accessing an element of an empty "
588 "collection such as a vector that has not been set to the "
598 <<
"Number " << arg1 <<
" must be larger than or equal "
604 template <
typename T>
608 <<
"Number " << arg1 <<
" must be larger than or equal "
618 <<
"Division " << arg1 <<
" by " << arg2
619 <<
" has remainder different from zero.");
630 "You are trying to use an iterator, but the iterator is "
631 "in an invalid state. This may indicate that the iterator "
632 "object has not been initialized, or that it has been "
633 "moved beyond the end of the range of valid elements.");
640 "You are trying to use an iterator, but the iterator is "
641 "pointing past the end of the range of valid elements. "
642 "It is not valid to dereference the iterator in this "
664 "You are trying an operation on a vector that is only "
665 "allowed if the vector has no ghost elements, but the "
666 "vector you are operating on does have ghost elements."
668 "Specifically, there are two kinds of operations that "
669 "are typically not allowed on vectors with ghost elements. "
670 "First, vectors with ghost elements are read-only "
671 "and cannot appear in operations that write into these "
672 "vectors with the exception of setting the entire vector "
673 "to zero. Second, reduction operations (such as computing "
674 "the norm of a vector, or taking dot products between "
675 "vectors) are not allowed to ensure that each vector "
676 "element is counted only once (as opposed to once for "
677 "the owner of the element plus once for each process "
678 "on which the element is stored as a ghost copy)."
680 "See the glossary entry on 'Ghosted vectors' for more "
689 <<
"Something went wrong when making cell " << arg1
690 <<
". Read the docs and the source code "
691 <<
"for more information.");
702 "A cell is flagged for coarsening, but either not all of its siblings "
703 "are active or flagged for coarsening as well. Please clean up all "
704 "coarsen flags on your triangulation via "
705 "Triangulation::prepare_coarsening_and_refinement() beforehand!");
715 "You are trying an operation of the form 'vector = C', "
716 "'matrix = C', or 'tensor = C' with a nonzero scalar value "
717 "'C'. However, such assignments are only allowed if the "
718 "C is zero, since the semantics for assigning any other "
719 "value are not clear. For example: one could interpret "
720 "assigning a matrix a value of 1 to mean the matrix has a "
721 "norm of 1, the matrix is the identity matrix, or the "
722 "matrix contains only 1s. Similar problems exist with "
723 "vectors and tensors. Hence, to avoid this ambiguity, such "
724 "assignments are not permitted.");
731 "You are attempting to use functionality that is only available "
732 "if deal.II was configured to use LAPACK, but when you configured "
733 "the library, cmake did not find a valid LAPACK library."
735 "You will have to ensure that your system has a usable LAPACK "
736 "installation and re-install deal.II, making sure that cmake "
737 "finds the LAPACK installation. You can check this by "
738 "looking at the summary printed at the end of the cmake "
746 "You are attempting to use functionality that requires that deal.II is configured "
747 "with HDF5 support. However, when you called 'cmake', HDF5 support "
750 "You will have to ensure that your system has a usable HDF5 "
751 "installation and re-install deal.II, making sure that cmake "
752 "finds the HDF5 installation. You can check this by "
753 "looking at the summary printed at the end of the cmake "
761 "You are attempting to use functionality that requires that deal.II is configured "
762 "with NetCDF support. However, when you called 'cmake', NetCDF support "
765 "You will have to ensure that your system has a usable NetCDF "
766 "installation and re-install deal.II, making sure that cmake "
767 "finds the NetCDF installation. You can check this by "
768 "looking at the summary printed at the end of the cmake "
776 "You are attempting to use functionality that is only available "
777 "if deal.II was configured to use MPI."
779 "You will have to ensure that your system has a usable MPI "
780 "installation and re-install deal.II, making sure that cmake "
781 "finds the MPI installation. You can check this by "
782 "looking at the summary printed at the end of the cmake "
790 "You are attempting to use functionality that is only available "
791 "if deal.II was configured to use the function parser which "
792 "relies on the muparser library, but cmake did not "
793 "find a valid muparser library on your system and also did "
794 "not choose the one that comes bundled with deal.II."
796 "You will have to ensure that your system has a usable muparser "
797 "installation and re-install deal.II, making sure that cmake "
798 "finds the muparser installation. You can check this by "
799 "looking at the summary printed at the end of the cmake "
808 "You are attempting to use functionality that is only available "
809 "if deal.II was configured to use Assimp, but cmake did not "
810 "find a valid Assimp library."
812 "You will have to ensure that your system has a usable Assimp "
813 "installation and re-install deal.II, making sure that cmake "
814 "finds the Assimp installation. You can check this by "
815 "looking at the summary printed at the end of the cmake "
823 "You are attempting to use functionality that is only available if deal.II "
824 "was configured to use Trilinos' SEACAS library (which provides ExodusII), "
825 "but cmake did not find a valid SEACAS library."
827 "You will have to ensure that your system has a usable ExodusII "
828 "installation and re-install deal.II, making sure that cmake "
829 "finds the ExodusII installation. You can check this by "
830 "looking at the summary printed at the end of the cmake "
838 "You are attempting to use functionality that is only available "
839 "if deal.II was configured to use CGAL, but cmake did not "
840 "find a valid CGAL library."
842 "You will have to ensure that your system has a usable CGAL "
843 "installation and re-install deal.II, making sure that cmake "
844 "finds the CGAL installation. You can check this by "
845 "looking at the summary printed at the end of the cmake "
853 "You are attempting to use functionality that is only available if deal.II "
854 "was configured to use GMSH's API, but cmake did not find a valid GMSH "
857 "You will have to ensure that your system has a usable GMSH "
858 "installation (including both the gmsh executable and the GMSH library) "
859 "and re-install deal.II, making sure that cmake finds the GMSH "
860 "installation. You can check this by looking at the summary printed at the "
861 "end of the cmake output.");
863#ifdef DEAL_II_WITH_MPI
899#ifdef DEAL_II_TRILINOS_WITH_SEACAS
937 "A user call-back function encountered a recoverable error, "
938 "but the underlying library that called the call-back did not "
939 "manage to recover from the error and aborted its operation."
941 "See the glossary entry on user call-back functions for more "
1082 template <
typename ExceptionType>
1087 const char *function,
1089 const char *exc_name,
1092 static_assert(std::is_base_of_v<ExceptionBase, ExceptionType>,
1093 "The provided exception must inherit from ExceptionBase.");
1095 e.set_fields(file, line, function, cond, exc_name);
1101 if (::deal_II_exceptions::internals::
1116 throw ::StandardExceptions::ExcInternalError();
1127 const char *function,
1130#if DEAL_II_KOKKOS_VERSION_GTE(3, 6, 0)
1134 KOKKOS_IF_ON_DEVICE(({ Kokkos::abort(msg); }))
1135 KOKKOS_IF_ON_HOST(({
1174#if DEAL_II_KOKKOS_VERSION_GTE(3, 6, 0)
1178 KOKKOS_IF_ON_DEVICE(
1179 ({ Kokkos::abort(
"DEAL_II_NOT_IMPLEMENTED reached."); }))
1180 KOKKOS_IF_ON_HOST(({
1226 template <
typename ExceptionType>
1230 const char *function,
1232 const char *exc_name,
1233 ExceptionType e)
noexcept
1235 static_assert(std::is_base_of_v<ExceptionBase, ExceptionType>,
1236 "The provided exception must inherit from ExceptionBase.");
1238 e.set_fields(file, line, function, cond, exc_name);
1267 template <
typename T,
typename U>
1271 using common_type = std::common_type_t<T, U>;
1272 return static_cast<common_type
>(t) ==
static_cast<common_type
>(u);
1290 template <
typename T,
typename U>
1294 using common_type = std::common_type_t<T, U>;
1295 return (
static_cast<common_type
>(t) <
static_cast<common_type
>(u));
1307 template <
typename F>
1310 template <
typename T,
typename U>
1316 template <
typename F>
void generate_message() const
void print_stack_trace(std::ostream &out) const
const char * get_exc_name() const
virtual ~ExceptionBase() noexcept override=default
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
virtual void print_info(std::ostream &out) const
virtual const char * what() const noexcept override
void print_exc_data(std::ostream &out) const
void * raw_stacktrace[25]
virtual void print_info(std::ostream &out) const override
virtual void print_info(std::ostream &out) const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_HOST_DEVICE
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
static ::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
#define DeclException0(Exception0)
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcOutOfMemory(std::size_t arg1)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcGhostsPresent()
static ::ExceptionBase & ExcFileNotOpen(std::string arg1)
static ::ExceptionBase & ExcNumberNotFinite(Number arg1)
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcNeedsAssimp()
static ::ExceptionBase & ExcNeedsFunctionparser()
static ::ExceptionBase & ExcNotMultiple(int arg1, int arg2)
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcNeedsMPI()
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
static ::ExceptionBase & ExcEmptyObject()
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
static ::ExceptionBase & ExcMemoryLeak(int arg1)
static ::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcNeedsGMSHAPI()
static ::ExceptionBase & ExcNeedsExodusII()
static ::ExceptionBase & ExcDimensionMismatch2(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcNeedsNetCDF()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
static ::ExceptionBase & ExcGridHasInvalidCell(int arg1)
static ::ExceptionBase & ExcPureFunctionCalled()
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDivideByZero()
static ::ExceptionBase & ExcNeedsHDF5()
static ::ExceptionBase & ExcNeedsLAPACK()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcNeedsCGAL()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcInvalidState()
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & RecoverableUserCallbackError()
static ::ExceptionBase & ExcInvalidIntegerConversion(long long arg1, long long arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcFunctionNonzeroReturn(std::string arg1, int arg2)
static ::ExceptionBase & ExcInconsistentCoarseningFlags()
constexpr bool compare_less_than(const T t, const U u)
void issue_error_noreturn(ExceptionHandling handling, const char *file, int line, const char *function, const char *cond, const char *exc_name, ExceptionType e)
@ abort_or_throw_on_exception
void abort(const ExceptionBase &exc) noexcept
void do_unreachable(const char *file, int line, const char *function, const char *msg)
void do_not_implemented(const char *file, int line, const char *function)
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
bool allow_abort_on_exception
constexpr bool compare_for_equality(const T t, const U u)
void issue_error_nothrow(const char *file, int line, const char *function, const char *cond, const char *exc_name, ExceptionType e) noexcept
void enable_abort_on_exception()
void disable_abort_on_exception()
void set_additional_assert_output(const char *const p)
void suppress_stacktrace_in_exceptions()
typename argument_type< F >::type argument_type_t