15#ifndef dealii_exceptions_h
16#define dealii_exceptions_h
25#include <Kokkos_Macros.hpp>
26#if DEAL_II_KOKKOS_VERSION_GTE(4, 2, 0)
27# include <Kokkos_Abort.hpp>
29# include <Kokkos_Core.hpp>
93 const
char *exc_name);
100 what() const noexcept override;
160#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
204 "A piece of code is attempting a division by zero. This is "
205 "likely going to lead to results that make no sense.");
219 std::complex<double>,
220 <<
"In a significant number of places, deal.II checks that some intermediate "
221 <<
"value is a finite number (as opposed to plus or minus infinity, or "
222 <<
"NaN/Not a Number). In the current function, we encountered a number "
223 <<
"that is not finite (its value is " << arg1 <<
" and therefore "
224 <<
"violates the current assertion).\n\n"
225 <<
"This may be due to the fact that some operation in this function "
226 <<
"created such a value, or because one of the arguments you passed "
227 <<
"to the function already had this value from some previous "
228 <<
"operation. In the latter case, this function only triggered the "
229 <<
"error but may not actually be responsible for the computation of "
230 <<
"the number that is not finite.\n\n"
231 <<
"There are two common cases where this situation happens. First, your "
232 <<
"code (or something in deal.II) divides by zero in a place where this "
233 <<
"should not happen. Or, you are trying to solve a linear system "
234 <<
"with an unsuitable solver (such as an indefinite or non-symmetric "
235 <<
"linear system using a Conjugate Gradient solver); such attempts "
236 <<
"oftentimes yield an operation somewhere that tries to divide "
237 <<
"by zero or take the square root of a negative value.\n\n"
238 <<
"In any case, when trying to find the source of the error, "
239 <<
"recall that the location where you are getting this error is "
240 <<
"simply the first place in the program where there is a check "
241 <<
"that a number (e.g., an element of a solution vector) is in fact "
242 <<
"finite, but that the actual error that computed the number "
243 <<
"may have happened far earlier. To find this location, you "
244 <<
"may want to add checks for finiteness in places of your "
245 <<
"program visited before the place where this error is produced. "
246 <<
"One way to check for finiteness is to use the 'AssertIsFinite' "
254 "Your program tried to allocate some memory but this "
255 "allocation failed. Typically, this either means that "
256 "you simply do not have enough memory in your system, "
257 "or that you are (erroneously) trying to allocate "
258 "a chunk of memory that is simply beyond all reasonable "
259 "size, for example because the size of the object has "
260 "been computed incorrectly."
262 "In the current case, the request was for "
263 << arg1 <<
" bytes.");
271 <<
"Destroying memory handler while " << arg1
272 <<
" objects are still allocated.");
278 "An input/output error has occurred. There are a number of "
279 "reasons why this may be happening, both for reading and "
280 "writing operations."
282 "If this happens during an operation that tries to read "
283 "data: First, you may be "
284 "trying to read from a file that doesn't exist or that is "
285 "not readable given its file permissions. Second, deal.II "
286 "uses this error at times if it tries to "
287 "read information from a file but where the information "
288 "in the file does not correspond to the expected format. "
289 "An example would be a truncated file, or a mesh file "
290 "that contains not only sections that describe the "
291 "vertices and cells, but also sections for additional "
292 "data that deal.II does not understand."
294 "If this happens during an operation that tries to write "
295 "data: you may be trying to write to a file to which file "
296 "or directory permissions do not allow you to write. A "
297 "typical example is where you specify an output file in "
298 "a directory that does not exist.");
308 <<
"Could not open file " << arg1
311 "If this happens during an operation that tries to read "
313 "trying to read from a file that doesn't exist or that is "
314 "not readable given its file permissions."
316 "If this happens during an operation that tries to write "
317 "data: you may be trying to write to a file to which file "
318 "or directory permissions do not allow you to write. A "
319 "typical example is where you specify an output file in "
320 "a directory that does not exist.");
331 "You are trying to use functionality in deal.II that is "
332 "currently not implemented. In many cases, this indicates "
333 "that there simply didn't appear much of a need for it, or "
334 "that the author of the original code did not have the "
335 "time to implement a particular case. If you hit this "
336 "exception, it is therefore worth the time to look into "
337 "the code to find out whether you may be able to "
338 "implement the missing functionality. If you do, please "
339 "consider providing a patch to the deal.II development "
340 "sources (see the deal.II website on how to contribute).");
363 "This exception -- which is used in many places in the "
364 "library -- usually indicates that some condition which "
365 "the author of the code thought must be satisfied at a "
366 "certain point in an algorithm, is not fulfilled. An "
367 "example would be that the first part of an algorithm "
368 "sorts elements of an array in ascending order, and "
369 "a second part of the algorithm later encounters an "
370 "element that is not larger than the previous one."
372 "There is usually not very much you can do if you "
373 "encounter such an exception since it indicates an error "
374 "in deal.II, not in your own program. Try to come up with "
375 "the smallest possible program that still demonstrates "
376 "the error and contact the deal.II mailing lists with it "
387 "You (or a place in the library) are trying to call a "
388 "function that is declared as a virtual function in a "
389 "base class but that has not been overridden in your "
392 "This exception happens in cases where the base class "
393 "cannot provide a useful default implementation for "
394 "the virtual function, but where we also do not want "
395 "to mark the function as abstract (i.e., with '=0' at the end) "
396 "because the function is not essential to the class in many "
397 "contexts. In cases like this, the base class provides "
398 "a dummy implementation that makes the compiler happy, but "
399 "that then throws the current exception."
401 "A concrete example would be the 'Function' class. It declares "
402 "the existence of 'value()' and 'gradient()' member functions, "
403 "and both are marked as 'virtual'. Derived classes have to "
404 "override these functions for the values and gradients of a "
405 "particular function. On the other hand, not every function "
406 "has a gradient, and even for those that do, not every program "
407 "actually needs to evaluate it. Consequently, there is no "
408 "*requirement* that a derived class actually override the "
409 "'gradient()' function (as there would be had it been marked "
410 "as abstract). But, since the base class cannot know how to "
411 "compute the gradient, if a derived class does not override "
412 "the 'gradient()' function and it is called anyway, then the "
413 "default implementation in the base class will simply throw "
416 "The exception you see is what happens in cases such as the "
417 "one just illustrated. To fix the problem, you need to "
418 "investigate whether the function being called should indeed have "
419 "been called; if the answer is 'yes', then you need to "
420 "implement the missing override in your class.");
427 <<
"Please provide an implementation for the function \""
437 <<
"The function \"" << arg1 <<
"\" returned the nonzero value " << arg2
438 <<
", but the calling site expected the return value to be zero. "
439 "This error often happens when the function in question is a 'callback', "
440 "that is a user-provided function called from somewhere within deal.II "
441 "or within an external library such as PETSc, Trilinos, SUNDIALS, etc., "
442 "that expect these callbacks to indicate errors via nonzero return "
463 <<
"You are trying to execute functionality that is "
464 <<
"impossible in " << arg1
465 <<
"d or simply does not make any sense.");
477 <<
"You are trying to execute functionality that is "
478 <<
"impossible in dimensions <" << arg1 <<
',' << arg2
479 <<
"> or simply does not make any sense.");
486 "In a check in the code, deal.II encountered a zero in "
487 "a place where this does not make sense. See the condition "
488 "that was being checked and that is printed further up "
489 "in the error message to get more information on what "
490 "the erroneous zero corresponds to.");
497 "The object you are trying to access is empty but it makes "
498 "no sense to attempt the operation you are trying on an "
511 <<
"Two sizes or dimensions were supposed to be equal, "
512 <<
"but aren't. They are " << arg1 <<
" and " << arg2 <<
'.');
522 <<
"Two integers should be equal to each other after a type conversion but "
523 <<
"aren't. A typical cause of this problem is that the integral types "
524 <<
"used by deal.II and an external library are different (e.g., one uses "
525 <<
"32-bit integers and the other uses 64-bit integers). The integers are "
526 << arg1 <<
" and " << arg2 <<
'.');
536 <<
"The size or dimension of one object, " << arg1
537 <<
" was supposed to be "
538 <<
"equal to one of two values, but isn't. The two possible "
539 <<
"values are " << arg2 <<
" and " << arg3 <<
'.');
558 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
','
561 " In the current case, this half-open range is in fact empty, "
562 "suggesting that you are accessing an element of an empty "
563 "collection such as a vector that has not been set to the "
582 template <
typename T>
588 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
','
591 " In the current case, this half-open range is in fact empty, "
592 "suggesting that you are accessing an element of an empty "
593 "collection such as a vector that has not been set to the "
603 <<
"Number " << arg1 <<
" must be larger than or equal "
609 template <
typename T>
613 <<
"Number " << arg1 <<
" must be larger than or equal "
623 <<
"Division " << arg1 <<
" by " << arg2
624 <<
" has remainder different from zero.");
635 "You are trying to use an iterator, but the iterator is "
636 "in an invalid state. This may indicate that the iterator "
637 "object has not been initialized, or that it has been "
638 "moved beyond the end of the range of valid elements.");
645 "You are trying to use an iterator, but the iterator is "
646 "pointing past the end of the range of valid elements. "
647 "It is not valid to dereference the iterator in this "
669 "You are trying an operation on a vector that is only "
670 "allowed if the vector has no ghost elements, but the "
671 "vector you are operating on does have ghost elements."
673 "Specifically, there are two kinds of operations that "
674 "are typically not allowed on vectors with ghost elements. "
675 "First, vectors with ghost elements are read-only "
676 "and cannot appear in operations that write into these "
677 "vectors. Second, reduction operations (such as computing "
678 "the norm of a vector, or taking dot products between "
679 "vectors) are not allowed to ensure that each vector "
680 "element is counted only once (as opposed to once for "
681 "the owner of the element plus once for each process "
682 "on which the element is stored as a ghost copy)."
684 "See the glossary entry on 'Ghosted vectors' for more "
693 <<
"Something went wrong when making cell " << arg1
694 <<
". Read the docs and the source code "
695 <<
"for more information.");
705 "You are trying an operation of the form 'vector = C', "
706 "'matrix = C', or 'tensor = C' with a nonzero scalar value "
707 "'C'. However, such assignments are only allowed if the "
708 "C is zero, since the semantics for assigning any other "
709 "value are not clear. For example: one could interpret "
710 "assigning a matrix a value of 1 to mean the matrix has a "
711 "norm of 1, the matrix is the identity matrix, or the "
712 "matrix contains only 1s. Similar problems exist with "
713 "vectors and tensors. Hence, to avoid this ambiguity, such "
714 "assignments are not permitted.");
721 "You are attempting to use functionality that is only available "
722 "if deal.II was configured to use LAPACK, but when you configured "
723 "the library, cmake did not find a valid LAPACK library."
725 "You will have to ensure that your system has a usable LAPACK "
726 "installation and re-install deal.II, making sure that cmake "
727 "finds the LAPACK installation. You can check this by "
728 "looking at the summary printed at the end of the cmake "
736 "You are attempting to use functionality that requires that deal.II is configured "
737 "with HDF5 support. However, when you called 'cmake', HDF5 support "
740 "You will have to ensure that your system has a usable HDF5 "
741 "installation and re-install deal.II, making sure that cmake "
742 "finds the HDF5 installation. You can check this by "
743 "looking at the summary printed at the end of the cmake "
751 "You are attempting to use functionality that is only available "
752 "if deal.II was configured to use MPI."
754 "You will have to ensure that your system has a usable MPI "
755 "installation and re-install deal.II, making sure that cmake "
756 "finds the MPI installation. You can check this by "
757 "looking at the summary printed at the end of the cmake "
765 "You are attempting to use functionality that is only available "
766 "if deal.II was configured to use the function parser which "
767 "relies on the muparser library, but cmake did not "
768 "find a valid muparser library on your system and also did "
769 "not choose the one that comes bundled with deal.II."
771 "You will have to ensure that your system has a usable muparser "
772 "installation and re-install deal.II, making sure that cmake "
773 "finds the muparser installation. You can check this by "
774 "looking at the summary printed at the end of the cmake "
783 "You are attempting to use functionality that is only available "
784 "if deal.II was configured to use Assimp, but cmake did not "
785 "find a valid Assimp library."
787 "You will have to ensure that your system has a usable Assimp "
788 "installation and re-install deal.II, making sure that cmake "
789 "finds the Assimp installation. You can check this by "
790 "looking at the summary printed at the end of the cmake "
798 "You are attempting to use functionality that is only available if deal.II "
799 "was configured to use Trilinos' SEACAS library (which provides ExodusII), "
800 "but cmake did not find a valid SEACAS library."
802 "You will have to ensure that your system has a usable ExodusII "
803 "installation and re-install deal.II, making sure that cmake "
804 "finds the ExodusII installation. You can check this by "
805 "looking at the summary printed at the end of the cmake "
813 "You are attempting to use functionality that is only available "
814 "if deal.II was configured to use CGAL, but cmake did not "
815 "find a valid CGAL library."
817 "You will have to ensure that your system has a usable CGAL "
818 "installation and re-install deal.II, making sure that cmake "
819 "finds the CGAL installation. You can check this by "
820 "looking at the summary printed at the end of the cmake "
823#ifdef DEAL_II_WITH_MPI
859#ifdef DEAL_II_TRILINOS_WITH_SEACAS
897 "A user call-back function encountered a recoverable error, "
898 "but the underlying library that called the call-back did not "
899 "manage to recover from the error and aborted its operation."
901 "See the glossary entry on user call-back functions for more "
1042 template <
typename ExceptionType>
1047 const char *function,
1049 const char *exc_name,
1052 static_assert(std::is_base_of_v<ExceptionBase, ExceptionType>,
1053 "The provided exception must inherit from ExceptionBase.");
1055 e.set_fields(file, line, function, cond, exc_name);
1061 if (::deal_II_exceptions::internals::
1076 throw ::StandardExceptions::ExcInternalError();
1094 template <
typename ExceptionType>
1098 const char *function,
1100 const char *exc_name,
1101 ExceptionType e)
noexcept
1103 static_assert(std::is_base_of_v<ExceptionBase, ExceptionType>,
1104 "The provided exception must inherit from ExceptionBase.");
1106 e.set_fields(file, line, function, cond, exc_name);
1126 template <
typename T,
typename U>
1130 using common_type = std::common_type_t<T, U>;
1131 return static_cast<common_type
>(t) ==
static_cast<common_type
>(u);
1140 template <
typename T,
typename U>
1144 using common_type = std::common_type_t<T, U>;
1145 return (
static_cast<common_type
>(t) <
static_cast<common_type
>(u));
1157 template <
typename F>
1160 template <
typename T,
typename U>
1166 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 & 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 & ExcNeedsExodusII()
static ::ExceptionBase & ExcDimensionMismatch2(std::size_t arg1, std::size_t arg2, std::size_t arg3)
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
static ::ExceptionBase & ExcGridHasInvalidCell(int arg1)
static ::ExceptionBase & ExcNumberNotFinite(std::complex< double > 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)
constexpr bool compare_less_than(const T &t, const U &u)
constexpr bool compare_for_equality(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_issue_error_nothrow(const ExceptionBase &e) noexcept
bool allow_abort_on_exception
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