16 #ifndef dealii_exceptions_h 17 #define dealii_exceptions_h 24 #include <type_traits> 26 #ifdef DEAL_II_WITH_CUDA 27 # include <cusolverSp.h> 28 # include <cusparse.h> 83 const char *exc_name);
90 what()
const noexcept
override;
132 const char *
function;
156 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 195 # define DeclException0(Exception0) \ 196 class Exception0 : public ::ExceptionBase \ 219 # define DeclExceptionMsg(Exception, defaulttext) \ 220 class Exception : public ::ExceptionBase \ 223 Exception(const std::string &msg = defaulttext) \ 226 virtual ~Exception() noexcept \ 229 print_info(std::ostream &out) const override \ 231 out << " " << arg << std::endl; \ 235 const std::string arg; \ 255 # define DeclException1(Exception1, type1, outsequence) \ 256 class Exception1 : public ::ExceptionBase \ 259 Exception1(type1 const &a1) \ 262 virtual ~Exception1() noexcept \ 265 print_info(std::ostream &out) const override \ 267 out << " " outsequence << std::endl; \ 292 # define DeclException2(Exception2, type1, type2, outsequence) \ 293 class Exception2 : public ::ExceptionBase \ 296 Exception2(type1 const &a1, type2 const &a2) \ 300 virtual ~Exception2() noexcept \ 303 print_info(std::ostream &out) const override \ 305 out << " " outsequence << std::endl; \ 331 # define DeclException3(Exception3, type1, type2, type3, outsequence) \ 332 class Exception3 : public ::ExceptionBase \ 335 Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \ 340 virtual ~Exception3() noexcept \ 343 print_info(std::ostream &out) const override \ 345 out << " " outsequence << std::endl; \ 372 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 373 class Exception4 : public ::ExceptionBase \ 376 Exception4(type1 const &a1, \ 385 virtual ~Exception4() noexcept \ 388 print_info(std::ostream &out) const override \ 390 out << " " outsequence << std::endl; \ 418 # define DeclException5( \ 419 Exception5, type1, type2, type3, type4, type5, outsequence) \ 420 class Exception5 : public ::ExceptionBase \ 423 Exception5(type1 const &a1, \ 434 virtual ~Exception5() noexcept \ 437 print_info(std::ostream &out) const override \ 439 out << " " outsequence << std::endl; \ 470 # define DeclException0(Exception0) \ 472 static ::ExceptionBase &Exception0() 493 # define DeclExceptionMsg(Exception, defaulttext) \ 496 static ::ExceptionBase &Exception() 515 # define DeclException1(Exception1, type1, outsequence) \ 518 static ::ExceptionBase &Exception1(type1 arg1) 538 # define DeclException2(Exception2, type1, type2, outsequence) \ 541 static ::ExceptionBase &Exception2(type1 arg1, type2 arg2) 561 # define DeclException3(Exception3, type1, type2, type3, outsequence) \ 564 static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3) 584 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 587 static ::ExceptionBase &Exception4(type1 arg1, \ 610 # define DeclException5( \ 611 Exception5, type1, type2, type3, type4, type5, outsequence) \ 614 static ::ExceptionBase &Exception5( \ 615 type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 642 "A piece of code is attempting a division by zero. This is " 643 "likely going to lead to results that make no sense.");
657 std::complex<double>,
658 <<
"In a significant number of places, deal.II checks that some intermediate " 659 <<
"value is a finite number (as opposed to plus or minus infinity, or " 660 <<
"NaN/Not a Number). In the current function, we encountered a number " 661 <<
"that is not finite (its value is " << arg1 <<
" and therefore " 662 <<
"violates the current assertion).\n\n" 663 <<
"This may be due to the fact that some operation in this function " 664 <<
"created such a value, or because one of the arguments you passed " 665 <<
"to the function already had this value from some previous " 666 <<
"operation. In the latter case, this function only triggered the " 667 <<
"error but may not actually be responsible for the computation of " 668 <<
"the number that is not finite.\n\n" 669 <<
"There are two common cases where this situation happens. First, your " 670 <<
"code (or something in deal.II) divides by zero in a place where this " 671 <<
"should not happen. Or, you are trying to solve a linear system " 672 <<
"with an unsuitable solver (such as an indefinite or non-symmetric " 673 <<
"linear system using a Conjugate Gradient solver); such attempts " 674 <<
"oftentimes yield an operation somewhere that tries to divide " 675 <<
"by zero or take the square root of a negative value.\n\n" 676 <<
"In any case, when trying to find the source of the error, " 677 <<
"recall that the location where you are getting this error is " 678 <<
"simply the first place in the program where there is a check " 679 <<
"that a number (e.g., an element of a solution vector) is in fact " 680 <<
"finite, but that the actual error that computed the number " 681 <<
"may have happened far earlier. To find this location, you " 682 <<
"may want to add checks for finiteness in places of your " 683 <<
"program visited before the place where this error is produced. " 684 <<
"One way to check for finiteness is to use the 'AssertIsFinite' " 692 "Your program tried to allocate some memory but this " 693 "allocation failed. Typically, this either means that " 694 "you simply do not have enough memory in your system, " 695 "or that you are (erroneously) trying to allocate " 696 "a chunk of memory that is simply beyond all reasonable " 697 "size, for example because the size of the object has " 698 "been computed incorrectly." 700 "In the current case, the request was for " 701 << arg1 <<
" bytes.");
709 <<
"Destroying memory handler while " << arg1
710 <<
" objects are still allocated.");
716 "An input/output error has occurred. There are a number of " 717 "reasons why this may be happening, both for reading and " 718 "writing operations." 720 "If this happens during an operation that tries to read " 721 "data: First, you may be " 722 "trying to read from a file that doesn't exist or that is " 723 "not readable given its file permissions. Second, deal.II " 724 "uses this error at times if it tries to " 725 "read information from a file but where the information " 726 "in the file does not correspond to the expected format. " 727 "An example would be a truncated file, or a mesh file " 728 "that contains not only sections that describe the " 729 "vertices and cells, but also sections for additional " 730 "data that deal.II does not understand." 732 "If this happens during an operation that tries to write " 733 "data: you may be trying to write to a file to which file " 734 "or directory permissions do not allow you to write. A " 735 "typical example is where you specify an output file in " 736 "a directory that does not exist.");
746 <<
"Could not open file " << arg1
749 "If this happens during an operation that tries to read " 751 "trying to read from a file that doesn't exist or that is " 752 "not readable given its file permissions." 754 "If this happens during an operation that tries to write " 755 "data: you may be trying to write to a file to which file " 756 "or directory permissions do not allow you to write. A " 757 "typical example is where you specify an output file in " 758 "a directory that does not exist.");
769 "You are trying to use functionality in deal.II that is " 770 "currently not implemented. In many cases, this indicates " 771 "that there simply didn't appear much of a need for it, or " 772 "that the author of the original code did not have the " 773 "time to implement a particular case. If you hit this " 774 "exception, it is therefore worth the time to look into " 775 "the code to find out whether you may be able to " 776 "implement the missing functionality. If you do, please " 777 "consider providing a patch to the deal.II development " 778 "sources (see the deal.II website on how to contribute).");
801 "This exception -- which is used in many places in the " 802 "library -- usually indicates that some condition which " 803 "the author of the code thought must be satisfied at a " 804 "certain point in an algorithm, is not fulfilled. An " 805 "example would be that the first part of an algorithm " 806 "sorts elements of an array in ascending order, and " 807 "a second part of the algorithm later encounters an " 808 "element that is not larger than the previous one." 810 "There is usually not very much you can do if you " 811 "encounter such an exception since it indicates an error " 812 "in deal.II, not in your own program. Try to come up with " 813 "the smallest possible program that still demonstrates " 814 "the error and contact the deal.II mailing lists with it " 825 "You (or a place in the library) are trying to call a " 826 "function that is declared as a virtual function in a " 827 "base class but that has not been overridden in your " 830 "This exception happens in cases where the base class " 831 "cannot provide a useful default implementation for " 832 "the virtual function, but where we also do not want " 833 "to mark the function as abstract (i.e., with '=0' at the end) " 834 "because the function is not essential to the class in many " 835 "contexts. In cases like this, the base class provides " 836 "a dummy implementation that makes the compiler happy, but " 837 "that then throws the current exception." 839 "A concrete example would be the 'Function' class. It declares " 840 "the existence of 'value()' and 'gradient()' member functions, " 841 "and both are marked as 'virtual'. Derived classes have to " 842 "override these functions for the values and gradients of a " 843 "particular function. On the other hand, not every function " 844 "has a gradient, and even for those that do, not every program " 845 "actually needs to evaluate it. Consequently, there is no " 846 "*requirement* that a derived class actually override the " 847 "'gradient()' function (as there would be had it been marked " 848 "as abstract). But, since the base class cannot know how to " 849 "compute the gradient, if a derived class does not override " 850 "the 'gradient()' function and it is called anyway, then the " 851 "default implementation in the base class will simply throw " 854 "The exception you see is what happens in cases such as the " 855 "one just illustrated. To fix the problem, you need to " 856 "investigate whether the function being called should indeed have " 857 "been called; if the answer is 'yes', then you need to " 858 "implement the missing override in your class.");
878 <<
"You are trying to execute functionality that is " 879 <<
"impossible in " << arg1
880 <<
"d or simply does not make any sense.");
892 <<
"You are trying to execute functionality that is " 893 <<
"impossible in dimensions <" << arg1 <<
"," << arg2
894 <<
"> or simply does not make any sense.");
901 "In a check in the code, deal.II encountered a zero in " 902 "a place where this does not make sense. See the condition " 903 "that was being checked and that is printed further up " 904 "in the error message to get more information on what " 905 "the erroneous zero corresponds to.");
912 "The object you are trying to access is empty but it makes " 913 "no sense to attempt the operation you are trying on an " 926 <<
"Dimension " << arg1 <<
" not equal to " << arg2 <<
".");
936 <<
"Dimension " << arg1 <<
" neither equal to " << arg2
937 <<
" nor to " << arg3 <<
".");
956 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 959 " In the current case, this half-open range is in fact empty, " 960 "suggesting that you are accessing an element of an empty " 961 "collection such as a vector that has not been set to the " 980 template <
typename T>
986 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 989 " In the current case, this half-open range is in fact empty, " 990 "suggesting that you are accessing an element of an empty " 991 "collection such as a vector that has not been set to the " 1001 <<
"Number " << arg1 <<
" must be larger than or equal " 1007 template <
typename T>
1011 <<
"Number " << arg1 <<
" must be larger than or equal " 1021 <<
"Division " << arg1 <<
" by " << arg2
1022 <<
" has remainder different from zero.");
1033 "You are trying to use an iterator, but the iterator is " 1034 "in an invalid state. This may indicate that the iterator " 1035 "object has not been initialized, or that it has been " 1036 "moved beyond the end of the range of valid elements.");
1043 "You are trying to use an iterator, but the iterator is " 1044 "pointing past the end of the range of valid elements. " 1045 "It is not valid to dereference the iterator in this " 1067 "You are trying an operation on a vector that is only " 1068 "allowed if the vector has no ghost elements, but the " 1069 "vector you are operating on does have ghost elements. " 1070 "Specifically, vectors with ghost elements are read-only " 1071 "and cannot appear in operations that write into these " 1074 "See the glossary entry on 'Ghosted vectors' for more " 1085 "You are trying an operation of the form 'vector=s' with " 1086 "a nonzero scalar value 's'. However, such assignments " 1087 "are only allowed if the right hand side is zero.");
1094 "You are attempting to use functionality that is only available " 1095 "if deal.II was configured to use LAPACK, but cmake did not " 1096 "find a valid LAPACK library.");
1103 "You are attempting to use functionality that is only available " 1104 "if deal.II was configured to use MPI.");
1111 "You are attempting to use functionality that is only available " 1112 "if deal.II was configured with DEAL_II_WITH_SIMPLEX_SUPPORT enabled.");
1119 "You are attempting to use functionality that is only available " 1120 "if deal.II was configured to use the function parser which " 1121 "relies on the muparser library, but cmake did not " 1122 "find a valid muparser library on your system and also did " 1123 "not choose the one that comes bundled with deal.II.");
1130 "You are attempting to use functionality that is only available " 1131 "if deal.II was configured to use Assimp, but cmake did not " 1132 "find a valid Assimp library.");
1134 #ifdef DEAL_II_WITH_CUDA 1147 <<
"There was an error in a cuSPARSE function: " << arg1);
1156 "You are attempting to use functionality that is only available if deal.II " 1157 "was configured to use Trilinos' SEACAS library (which provides ExodusII), " 1158 "but cmake did not find find a valid SEACAS library.");
1160 #ifdef DEAL_II_WITH_MPI 1185 ExcMPI(
const int error_code);
1188 print_info(std::ostream &out)
const override;
1192 #endif // DEAL_II_WITH_MPI 1196 #ifdef DEAL_II_TRILINOS_WITH_SEACAS 1213 ExcExodusII(
const int error_code);
1219 print_info(std::ostream &out)
const override;
1224 const int error_code;
1226 #endif // DEAL_II_TRILINOS_WITH_SEACAS 1351 template <
class ExceptionType>
1356 const char *
function,
1358 const char * exc_name,
1361 e.set_fields(file, line,
function, cond, exc_name);
1399 template <
class ExceptionType>
1403 const char *
function,
1405 const char * exc_name,
1406 ExceptionType e) noexcept
1408 static_assert(std::is_base_of<ExceptionBase, ExceptionType>::value,
1409 "The provided exception must inherit from ExceptionBase.");
1416 #ifdef DEAL_II_WITH_CUDA 1465 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1466 # define Assert(cond, exc) \ 1468 if (__builtin_expect(!(cond), false)) \ 1469 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1470 ::deal_II_exceptions::internals:: \ 1471 abort_or_throw_on_exception, \ 1474 __PRETTY_FUNCTION__, \ 1480 # define Assert(cond, exc) \ 1483 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1484 ::deal_II_exceptions::internals:: \ 1485 abort_or_throw_on_exception, \ 1488 __PRETTY_FUNCTION__, \ 1495 # define Assert(cond, exc) \ 1528 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1529 # define AssertNothrow(cond, exc) \ 1531 if (__builtin_expect(!(cond), false)) \ 1532 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1533 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1536 # define AssertNothrow(cond, exc) \ 1539 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1540 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1544 # define AssertNothrow(cond, exc) \ 1575 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1576 # define AssertThrow(cond, exc) \ 1578 if (__builtin_expect(!(cond), false)) \ 1579 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1580 ::deal_II_exceptions::internals::throw_on_exception, \ 1583 __PRETTY_FUNCTION__, \ 1589 # define AssertThrow(cond, exc) \ 1592 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1593 ::deal_II_exceptions::internals::throw_on_exception, \ 1596 __PRETTY_FUNCTION__, \ 1623 #define AssertDimension(dim1, dim2) \ 1624 Assert(static_cast<typename ::internal::argument_type<void( \ 1625 typename std::common_type<decltype(dim1), \ 1626 decltype(dim2)>::type)>::type>(dim1) == \ 1627 static_cast<typename ::internal::argument_type<void( \ 1628 typename std::common_type<decltype(dim1), \ 1629 decltype(dim2)>::type)>::type>(dim2), \ 1630 ::ExcDimensionMismatch((dim1), (dim2))) 1650 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \ 1651 AssertDimension(VEC.size(), DIM1); \ 1652 for (const auto &subvector : VEC) \ 1655 AssertDimension(subvector.size(), DIM2); \ 1663 template <
typename T>
1665 template <
typename T,
typename U>
1691 #define AssertIndexRange(index, range) \ 1693 static_cast<typename ::internal::argument_type<void( \ 1694 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1696 static_cast<typename ::internal::argument_type<void( \ 1697 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1699 ExcIndexRangeType<typename ::internal::argument_type<void( \ 1700 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1701 type>((index), 0, (range))) 1722 #define AssertIsFinite(number) \ 1723 Assert(::numbers::is_finite(number), \ 1724 ::ExcNumberNotFinite(std::complex<double>(number))) 1726 #ifdef DEAL_II_WITH_MPI 1747 # define AssertThrowMPI(error_code) \ 1748 AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code)) 1750 # define AssertThrowMPI(error_code) \ 1752 #endif // DEAL_II_WITH_MPI 1754 #ifdef DEAL_II_WITH_CUDA 1773 # define AssertCuda(error_code) \ 1774 Assert(error_code == cudaSuccess, \ 1775 ::ExcCudaError(cudaGetErrorString(error_code))) 1777 # define AssertCuda(error_code) \ 1779 (void)(error_code); \ 1800 # define AssertNothrowCuda(error_code) \ 1801 AssertNothrow(error_code == cudaSuccess, \ 1802 ::ExcCudaError(cudaGetErrorString(error_code))) 1804 # define AssertNothrowCuda(error_code) \ 1806 (void)(error_code); \ 1828 # define AssertCudaKernel() \ 1830 cudaError_t local_error_code = cudaPeekAtLastError(); \ 1831 AssertCuda(local_error_code); \ 1832 local_error_code = cudaDeviceSynchronize(); \ 1833 AssertCuda(local_error_code) \ 1836 # define AssertCudaKernel() \ 1858 # define AssertCusparse(error_code) \ 1860 error_code == CUSPARSE_STATUS_SUCCESS, \ 1862 deal_II_exceptions::internals::get_cusparse_error_string( \ 1865 # define AssertCusparse(error_code) \ 1867 (void)(error_code); \ 1888 # define AssertNothrowCusparse(error_code) \ 1890 error_code == CUSPARSE_STATUS_SUCCESS, \ 1892 deal_II_exceptions::internals::get_cusparse_error_string( \ 1895 # define AssertNothrowCusparse(error_code) \ 1897 (void)(error_code); \ 1919 # define AssertCusolver(error_code) \ 1921 error_code == CUSOLVER_STATUS_SUCCESS, \ 1923 deal_II_exceptions::internals::get_cusolver_error_string( \ 1926 # define AssertCusolver(error_code) \ 1928 (void)(error_code); \ 1934 #ifdef DEAL_II_TRILINOS_WITH_SEACAS 1952 # define AssertThrowExodusII(error_code) \ 1953 AssertThrow(error_code == 0, ExcExodusII(error_code)); 1954 #endif // DEAL_II_TRILINOS_WITH_SEACAS static ::ExceptionBase & ExcCudaError(const char *arg1)
static ::ExceptionBase & ExcPureFunctionCalled()
static ::ExceptionBase & ExcNeedsFunctionparser()
static ::ExceptionBase & ExcNeedsExodusII()
static ::ExceptionBase & ExcNeedsMPI()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
void suppress_stacktrace_in_exceptions()
static ::ExceptionBase & ExcIO()
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
static ::ExceptionBase & ExcDimensionMismatch2(int arg1, int arg2, int arg3)
virtual ~ExceptionBase() noexcept override
std::string get_cusolver_error_string(const cusolverStatus_t error_code)
void set_additional_assert_output(const char *const p)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
static ::ExceptionBase & ExcDivideByZero()
void * raw_stacktrace[25]
virtual void print_info(std::ostream &out) const
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcNeedsLAPACK()
static ::ExceptionBase & ExcNeedsSimplexSupport()
ExceptionBase operator=(const ExceptionBase &)=delete
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
virtual const char * what() const noexcept override
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMemoryLeak(int arg1)
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
static ::ExceptionBase & ExcOutOfMemory(std::size_t arg1)
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException0(Exception0)
void abort(const ExceptionBase &exc) noexcept
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNeedsAssimp()
static ::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
void print_stack_trace(std::ostream &out) const
static ::ExceptionBase & ExcGhostsPresent()
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcNumberNotFinite(std::complex< double > arg1)
void issue_error_noreturn(ExceptionHandling handling, const char *file, int line, const char *function, const char *cond, const char *exc_name, ExceptionType e)
void issue_error_nothrow(const char *file, int line, const char *function, const char *cond, const char *exc_name, ExceptionType e) noexcept
#define DEAL_II_NAMESPACE_OPEN
static ::ExceptionBase & ExcCusparseError(std::string arg1)
static ::ExceptionBase & ExcEmptyObject()
bool allow_abort_on_exception
void print_exc_data(std::ostream &out) const
static ::ExceptionBase & ExcNotMultiple(int arg1, int arg2)
static ::ExceptionBase & ExcNotImplemented()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
void generate_message() const
void disable_abort_on_exception()
const char * get_exc_name() const
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcFileNotOpen(std::string arg1)
static ::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
static ::ExceptionBase & ExcInternalError()