16 #ifndef dealii_exceptions_h 17 #define dealii_exceptions_h 19 #include <deal.II/base/config.h> 24 #include <type_traits> 26 #ifdef DEAL_II_WITH_CUDA 27 # include <cusolverSp.h> 28 # include <cusparse.h> 32 DEAL_II_NAMESPACE_OPEN
84 const char *exc_name);
91 what()
const noexcept
override;
133 const char *
function;
157 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 197 # define DeclException0(Exception0) \ 198 class Exception0 : public ::ExceptionBase \ 221 # define DeclExceptionMsg(Exception, defaulttext) \ 222 class Exception : public ::ExceptionBase \ 225 Exception(const std::string &msg = defaulttext) \ 228 virtual ~Exception() noexcept \ 231 print_info(std::ostream &out) const override \ 233 out << " " << arg << std::endl; \ 237 const std::string arg; \ 257 # define DeclException1(Exception1, type1, outsequence) \ 258 class Exception1 : public ::ExceptionBase \ 261 Exception1(type1 const &a1) \ 264 virtual ~Exception1() noexcept \ 267 print_info(std::ostream &out) const override \ 269 out << " " outsequence << std::endl; \ 294 # define DeclException2(Exception2, type1, type2, outsequence) \ 295 class Exception2 : public ::ExceptionBase \ 298 Exception2(type1 const &a1, type2 const &a2) \ 302 virtual ~Exception2() noexcept \ 305 print_info(std::ostream &out) const override \ 307 out << " " outsequence << std::endl; \ 333 # define DeclException3(Exception3, type1, type2, type3, outsequence) \ 334 class Exception3 : public ::ExceptionBase \ 337 Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \ 342 virtual ~Exception3() noexcept \ 345 print_info(std::ostream &out) const override \ 347 out << " " outsequence << std::endl; \ 374 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 375 class Exception4 : public ::ExceptionBase \ 378 Exception4(type1 const &a1, \ 387 virtual ~Exception4() noexcept \ 390 print_info(std::ostream &out) const override \ 392 out << " " outsequence << std::endl; \ 420 # define DeclException5( \ 421 Exception5, type1, type2, type3, type4, type5, outsequence) \ 422 class Exception5 : public ::ExceptionBase \ 425 Exception5(type1 const &a1, \ 436 virtual ~Exception5() noexcept \ 439 print_info(std::ostream &out) const override \ 441 out << " " outsequence << std::endl; \ 473 # define DeclException0(Exception0) \ 475 static ::ExceptionBase &Exception0() 496 # define DeclExceptionMsg(Exception, defaulttext) \ 499 static ::ExceptionBase &Exception() 518 # define DeclException1(Exception1, type1, outsequence) \ 521 static ::ExceptionBase &Exception1(type1 arg1) 541 # define DeclException2(Exception2, type1, type2, outsequence) \ 544 static ::ExceptionBase &Exception2(type1 arg1, type2 arg2) 564 # define DeclException3(Exception3, type1, type2, type3, outsequence) \ 567 static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3) 587 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 590 static ::ExceptionBase &Exception4(type1 arg1, \ 613 # define DeclException5( \ 614 Exception5, type1, type2, type3, type4, type5, outsequence) \ 617 static ::ExceptionBase &Exception5( \ 618 type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 645 "A piece of code is attempting a division by zero. This is " 646 "likely going to lead to results that make no sense.");
660 std::complex<double>,
661 <<
"In a significant number of places, deal.II checks that some intermediate " 662 <<
"value is a finite number (as opposed to plus or minus infinity, or " 663 <<
"NaN/Not a Number). In the current function, we encountered a number " 664 <<
"that is not finite (its value is " << arg1 <<
" and therefore " 665 <<
"violates the current assertion).\n\n" 666 <<
"This may be due to the fact that some operation in this function " 667 <<
"created such a value, or because one of the arguments you passed " 668 <<
"to the function already had this value from some previous " 669 <<
"operation. In the latter case, this function only triggered the " 670 <<
"error but may not actually be responsible for the computation of " 671 <<
"the number that is not finite.\n\n" 672 <<
"There are two common cases where this situation happens. First, your " 673 <<
"code (or something in deal.II) divides by zero in a place where this " 674 <<
"should not happen. Or, you are trying to solve a linear system " 675 <<
"with an unsuitable solver (such as an indefinite or non-symmetric " 676 <<
"linear system using a Conjugate Gradient solver); such attempts " 677 <<
"oftentimes yield an operation somewhere that tries to divide " 678 <<
"by zero or take the square root of a negative value.\n\n" 679 <<
"In any case, when trying to find the source of the error, " 680 <<
"recall that the location where you are getting this error is " 681 <<
"simply the first place in the program where there is a check " 682 <<
"that a number (e.g., an element of a solution vector) is in fact " 683 <<
"finite, but that the actual error that computed the number " 684 <<
"may have happened far earlier. To find this location, you " 685 <<
"may want to add checks for finiteness in places of your " 686 <<
"program visited before the place where this error is produced." 687 <<
"One way to check for finiteness is to use the 'AssertIsFinite' " 694 "Your program tried to allocate some memory but this " 695 "allocation failed. Typically, this either means that " 696 "you simply do not have enough memory in your system, " 697 "or that you are (erroneously) trying to allocate " 698 "a chunk of memory that is simply beyond all reasonable " 699 "size, for example because the size of the object has " 700 "been computed incorrectly.");
708 <<
"Destroying memory handler while " << arg1
709 <<
" objects are still allocated.");
715 "An input/output error has occurred. There are a number of " 716 "reasons why this may be happening, both for reading and " 717 "writing operations." 719 "If this happens during an operation that tries to read " 720 "data: First, you may be " 721 "trying to read from a file that doesn't exist or that is " 722 "not readable given its file permissions. Second, deal.II " 723 "uses this error at times if it tries to " 724 "read information from a file but where the information " 725 "in the file does not correspond to the expected format. " 726 "An example would be a truncated file, or a mesh file " 727 "that contains not only sections that describe the " 728 "vertices and cells, but also sections for additional " 729 "data that deal.II does not understand." 731 "If this happens during an operation that tries to write " 732 "data: you may be trying to write to a file to which file " 733 "or directory permissions do not allow you to write. A " 734 "typical example is where you specify an output file in " 735 "a directory that does not exist.");
745 <<
"Could not open file " << arg1 <<
".");
756 "You are trying to use functionality in deal.II that is " 757 "currently not implemented. In many cases, this indicates " 758 "that there simply didn't appear much of a need for it, or " 759 "that the author of the original code did not have the " 760 "time to implement a particular case. If you hit this " 761 "exception, it is therefore worth the time to look into " 762 "the code to find out whether you may be able to " 763 "implement the missing functionality. If you do, please " 764 "consider providing a patch to the deal.II development " 765 "sources (see the deal.II website on how to contribute).");
788 "This exception -- which is used in many places in the " 789 "library -- usually indicates that some condition which " 790 "the author of the code thought must be satisfied at a " 791 "certain point in an algorithm, is not fulfilled. An " 792 "example would be that the first part of an algorithm " 793 "sorts elements of an array in ascending order, and " 794 "a second part of the algorithm later encounters an " 795 "element that is not larger than the previous one." 797 "There is usually not very much you can do if you " 798 "encounter such an exception since it indicates an error " 799 "in deal.II, not in your own program. Try to come up with " 800 "the smallest possible program that still demonstrates " 801 "the error and contact the deal.II mailing lists with it " 812 "You (or a place in the library) are trying to call a " 813 "function that is declared as a virtual function in a " 814 "base class but that has not been overridden in your " 817 "This exception happens in cases where the base class " 818 "cannot provide a useful default implementation for " 819 "the virtual function, but where we also do not want " 820 "to mark the function as abstract (i.e., with '=0' at the end) " 821 "because the function is not essential to the class in many " 822 "contexts. In cases like this, the base class provides " 823 "a dummy implementation that makes the compiler happy, but " 824 "that then throws the current exception." 826 "A concrete example would be the 'Function' class. It declares " 827 "the existence of 'value()' and 'gradient()' member functions, " 828 "and both are marked as 'virtual'. Derived classes have to " 829 "override these functions for the values and gradients of a " 830 "particular function. On the other hand, not every function " 831 "has a gradient, and even for those that do, not every program " 832 "actually needs to evaluate it. Consequently, there is no " 833 "*requirement* that a derived class actually override the " 834 "'gradient()' function (as there would be had it been marked " 835 "as abstract). But, since the base class cannot know how to " 836 "compute the gradient, if a derived class does not override " 837 "the 'gradient()' function and it is called anyway, then the " 838 "default implementation in the base class will simply throw " 841 "The exception you see is what happens in cases such as the " 842 "one just illustrated. To fix the problem, you need to " 843 "investigate whether the function being called should indeed have " 844 "been called; if the answer is 'yes', then you need to " 845 "implement the missing override in your class.");
865 <<
"You are trying to execute functionality that is " 866 <<
"impossible in " << arg1
867 <<
"d or simply does not make any sense.");
879 <<
"You are trying to execute functionality that is " 880 <<
"impossible in dimensions <" << arg1 <<
"," << arg2
881 <<
"> or simply does not make any sense.");
888 "In a check in the code, deal.II encountered a zero in " 889 "a place where this does not make sense. See the condition " 890 "that was being checked and that is printed further up " 891 "in the error message to get more information on what " 892 "the erroneous zero corresponds to.");
899 "The object you are trying to access is empty but it makes " 900 "no sense to attempt the operation you are trying on an " 913 <<
"Dimension " << arg1 <<
" not equal to " << arg2 <<
".");
923 <<
"Dimension " << arg1 <<
" neither equal to " << arg2
924 <<
" nor to " << arg3 <<
".");
943 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 946 " In the current case, this half-open range is in fact empty, " 947 "suggesting that you are accessing an element of an empty " 948 "collection such as a vector that has not been set to the " 967 template <
typename T>
973 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 976 " In the current case, this half-open range is in fact empty, " 977 "suggesting that you are accessing an element of an empty " 978 "collection such as a vector that has not been set to the " 988 <<
"Number " << arg1 <<
" must be larger than or equal " 994 template <
typename T>
998 <<
"Number " << arg1 <<
" must be larger than or equal " 1008 <<
"Division " << arg1 <<
" by " << arg2
1009 <<
" has remainder different from zero.");
1020 "You are trying to use an iterator, but the iterator is " 1021 "in an invalid state. This may indicate that the iterator " 1022 "object has not been initialized, or that it has been " 1023 "moved beyond the end of the range of valid elements.");
1030 "You are trying to use an iterator, but the iterator is " 1031 "pointing past the end of the range of valid elements. " 1032 "It is not valid to dereference the iterator in this " 1054 "You are trying an operation on a vector that is only " 1055 "allowed if the vector has no ghost elements, but the " 1056 "vector you are operating on does have ghost elements. " 1057 "Specifically, vectors with ghost elements are read-only " 1058 "and cannot appear in operations that write into these " 1061 "See the glossary entry on 'Ghosted vectors' for more " 1072 "You are trying an operation of the form 'vector=s' with " 1073 "a nonzero scalar value 's'. However, such assignments " 1074 "are only allowed if the right hand side is zero.");
1081 "You are attempting to use functionality that is only available " 1082 "if deal.II was configured to use LAPACK, but cmake did not " 1083 "find a valid LAPACK library.");
1092 "You are attempting to use functionality that is only available " 1093 "if deal.II was configured to use NetCDF, but cmake did not " 1094 "find a valid NetCDF library.");
1101 "You are attempting to use functionality that is only available " 1102 "if deal.II was configured to use the function parser which " 1103 "relies on the muparser library, but cmake did not " 1104 "find a valid muparser library on your system and also did " 1105 "not choose the one that comes bundled with deal.II.");
1112 "You are attempting to use functionality that is only available " 1113 "if deal.II was configured to use Assimp, but cmake did not " 1114 "find a valid Assimp library.");
1116 #ifdef DEAL_II_WITH_CUDA 1129 <<
"There was an error in a cuSPARSE function: " << arg1);
1133 #ifdef DEAL_II_WITH_MPI 1159 ExcMPI(
const int error_code);
1162 print_info(std::ostream &out)
const override;
1164 const int error_code;
1166 #endif // DEAL_II_WITH_MPI 1291 template <
class ExceptionType>
1296 const char *
function,
1298 const char * exc_name,
1301 e.set_fields(file, line,
function, cond, exc_name);
1339 template <
class ExceptionType>
1343 const char *
function,
1345 const char * exc_name,
1346 ExceptionType e) noexcept
1348 static_assert(std::is_base_of<ExceptionBase, ExceptionType>::value,
1349 "The provided exception must inherit from ExceptionBase.");
1351 e.set_fields(file, line,
function, cond, exc_name);
1356 #ifdef DEAL_II_WITH_CUDA 1406 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1407 # define Assert(cond, exc) \ 1409 if (__builtin_expect(!(cond), false)) \ 1410 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1411 ::deal_II_exceptions::internals:: \ 1412 abort_or_throw_on_exception, \ 1415 __PRETTY_FUNCTION__, \ 1421 # define Assert(cond, exc) \ 1424 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1425 ::deal_II_exceptions::internals:: \ 1426 abort_or_throw_on_exception, \ 1429 __PRETTY_FUNCTION__, \ 1436 # define Assert(cond, exc) \ 1470 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1471 # define AssertNothrow(cond, exc) \ 1473 if (__builtin_expect(!(cond), false)) \ 1474 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1475 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1478 # define AssertNothrow(cond, exc) \ 1481 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1482 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1486 # define AssertNothrow(cond, exc) \ 1518 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1519 # define AssertThrow(cond, exc) \ 1521 if (__builtin_expect(!(cond), false)) \ 1522 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1523 ::deal_II_exceptions::internals::throw_on_exception, \ 1526 __PRETTY_FUNCTION__, \ 1532 # define AssertThrow(cond, exc) \ 1535 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1536 ::deal_II_exceptions::internals::throw_on_exception, \ 1539 __PRETTY_FUNCTION__, \ 1567 #define AssertDimension(dim1, dim2) \ 1568 Assert(static_cast<typename ::internal::argument_type<void( \ 1569 typename std::common_type<decltype(dim1), \ 1570 decltype(dim2)>::type)>::type>(dim1) == \ 1571 static_cast<typename ::internal::argument_type<void( \ 1572 typename std::common_type<decltype(dim1), \ 1573 decltype(dim2)>::type)>::type>(dim2), \ 1574 ::ExcDimensionMismatch((dim1), (dim2))) 1595 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \ 1596 AssertDimension(VEC.size(), DIM1); \ 1597 for (const auto &subvector : VEC) \ 1600 AssertDimension(subvector.size(), DIM2); \ 1608 template <
typename T>
1609 struct argument_type;
1610 template <
typename T,
typename U>
1611 struct argument_type<T(U)>
1637 #define AssertIndexRange(index, range) \ 1639 static_cast<typename ::internal::argument_type<void( \ 1640 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1642 static_cast<typename ::internal::argument_type<void( \ 1643 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1645 ExcIndexRangeType<typename ::internal::argument_type<void( \ 1646 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1647 type>((index), 0, (range))) 1669 #define AssertIsFinite(number) \ 1670 Assert(::numbers::is_finite(number), \ 1671 ::ExcNumberNotFinite(std::complex<double>(number))) 1673 #ifdef DEAL_II_WITH_MPI 1695 # define AssertThrowMPI(error_code) \ 1696 AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code)) 1698 # define AssertThrowMPI(error_code) \ 1700 #endif // DEAL_II_WITH_MPI 1702 #ifdef DEAL_II_WITH_CUDA 1722 # define AssertCuda(error_code) \ 1723 Assert(error_code == cudaSuccess, \ 1724 ::ExcCudaError(cudaGetErrorString(error_code))) 1726 # define AssertCuda(error_code) \ 1728 (void)(error_code); \ 1750 # define AssertNothrowCuda(error_code) \ 1751 AssertNothrow(error_code == cudaSuccess, \ 1752 ::ExcCudaError(cudaGetErrorString(error_code))) 1754 # define AssertNothrowCuda(error_code) \ 1756 (void)(error_code); \ 1779 # define AssertCusparse(error_code) \ 1781 error_code == CUSPARSE_STATUS_SUCCESS, \ 1783 deal_II_exceptions::internals::get_cusparse_error_string( \ 1786 # define AssertCusparse(error_code) \ 1788 (void)(error_code); \ 1810 # define AssertNothrowCusparse(error_code) \ 1812 error_code == CUSPARSE_STATUS_SUCCESS, \ 1814 deal_II_exceptions::internals::get_cusparse_error_string( \ 1817 # define AssertNothrowCusparse(error_code) \ 1819 (void)(error_code); \ 1842 # define AssertCusolver(error_code) \ 1844 error_code == CUSOLVER_STATUS_SUCCESS, \ 1846 deal_II_exceptions::internals::get_cusolver_error_string( \ 1849 # define AssertCusolver(error_code) \ 1851 (void)(error_code); \ 1859 DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcCudaError(const char *arg1)
static ::ExceptionBase & ExcPureFunctionCalled()
static ::ExceptionBase & ExcNeedsFunctionparser()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
void suppress_stacktrace_in_exceptions()
static ::ExceptionBase & ExcIO()
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 & ExcOutOfMemory()
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()
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
static ::ExceptionBase & ExcNeedsNetCDF()
#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
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException0(Exception0)
void abort(const ExceptionBase &exc) noexcept
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)
virtual void print_info(std::ostream &out) const override
void issue_error_nothrow(const char *file, int line, const char *function, const char *cond, const char *exc_name, ExceptionType e) noexcept
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()