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 186 # define DeclException0(Exception0) \ 187 class Exception0 : public ::ExceptionBase \ 199 # define DeclExceptionMsg(Exception, defaulttext) \ 200 class Exception : public ::ExceptionBase \ 203 Exception(const std::string &msg = defaulttext) \ 206 virtual ~Exception() noexcept \ 209 print_info(std::ostream &out) const override \ 211 out << " " << arg << std::endl; \ 215 const std::string arg; \ 224 # define DeclException1(Exception1, type1, outsequence) \ 225 class Exception1 : public ::ExceptionBase \ 228 Exception1(type1 const &a1) \ 231 virtual ~Exception1() noexcept \ 234 print_info(std::ostream &out) const override \ 236 out << " " outsequence << std::endl; \ 250 # define DeclException2(Exception2, type1, type2, outsequence) \ 251 class Exception2 : public ::ExceptionBase \ 254 Exception2(type1 const &a1, type2 const &a2) \ 258 virtual ~Exception2() noexcept \ 261 print_info(std::ostream &out) const override \ 263 out << " " outsequence << std::endl; \ 278 # define DeclException3(Exception3, type1, type2, type3, outsequence) \ 279 class Exception3 : public ::ExceptionBase \ 282 Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \ 287 virtual ~Exception3() noexcept \ 290 print_info(std::ostream &out) const override \ 292 out << " " outsequence << std::endl; \ 308 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 309 class Exception4 : public ::ExceptionBase \ 312 Exception4(type1 const &a1, \ 321 virtual ~Exception4() noexcept \ 324 print_info(std::ostream &out) const override \ 326 out << " " outsequence << std::endl; \ 343 # define DeclException5( \ 344 Exception5, type1, type2, type3, type4, type5, outsequence) \ 345 class Exception5 : public ::ExceptionBase \ 348 Exception5(type1 const &a1, \ 359 virtual ~Exception5() noexcept \ 362 print_info(std::ostream &out) const override \ 364 out << " " outsequence << std::endl; \ 385 # define DeclException0(Exception0) \ 387 static ::ExceptionBase &Exception0() 397 # define DeclExceptionMsg(Exception, defaulttext) \ 400 static ::ExceptionBase &Exception() 408 # define DeclException1(Exception1, type1, outsequence) \ 411 static ::ExceptionBase &Exception1(type1 arg1) 420 # define DeclException2(Exception2, type1, type2, outsequence) \ 423 static ::ExceptionBase &Exception2(type1 arg1, type2 arg2) 432 # define DeclException3(Exception3, type1, type2, type3, outsequence) \ 435 static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3) 444 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 447 static ::ExceptionBase &Exception4(type1 arg1, \ 459 # define DeclException5( \ 460 Exception5, type1, type2, type3, type4, type5, outsequence) \ 463 static ::ExceptionBase &Exception5( \ 464 type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 491 "A piece of code is attempting a division by zero. This is " 492 "likely going to lead to results that make no sense.");
506 std::complex<double>,
507 <<
"In a significant number of places, deal.II checks that some intermediate " 508 <<
"value is a finite number (as opposed to plus or minus infinity, or " 509 <<
"NaN/Not a Number). In the current function, we encountered a number " 510 <<
"that is not finite (its value is " << arg1 <<
" and therefore " 511 <<
"violates the current assertion).\n\n" 512 <<
"This may be due to the fact that some operation in this function " 513 <<
"created such a value, or because one of the arguments you passed " 514 <<
"to the function already had this value from some previous " 515 <<
"operation. In the latter case, this function only triggered the " 516 <<
"error but may not actually be responsible for the computation of " 517 <<
"the number that is not finite.\n\n" 518 <<
"There are two common cases where this situation happens. First, your " 519 <<
"code (or something in deal.II) divides by zero in a place where this " 520 <<
"should not happen. Or, you are trying to solve a linear system " 521 <<
"with an unsuitable solver (such as an indefinite or non-symmetric " 522 <<
"linear system using a Conjugate Gradient solver); such attempts " 523 <<
"oftentimes yield an operation somewhere that tries to divide " 524 <<
"by zero or take the square root of a negative value.\n\n" 525 <<
"In any case, when trying to find the source of the error, " 526 <<
"recall that the location where you are getting this error is " 527 <<
"simply the first place in the program where there is a check " 528 <<
"that a number (e.g., an element of a solution vector) is in fact " 529 <<
"finite, but that the actual error that computed the number " 530 <<
"may have happened far earlier. To find this location, you " 531 <<
"may want to add checks for finiteness in places of your " 532 <<
"program visited before the place where this error is produced." 533 <<
"One way to check for finiteness is to use the 'AssertIsFinite' " 540 "Your program tried to allocate some memory but this " 541 "allocation failed. Typically, this either means that " 542 "you simply do not have enough memory in your system, " 543 "or that you are (erroneously) trying to allocate " 544 "a chunk of memory that is simply beyond all reasonable " 545 "size, for example because the size of the object has " 546 "been computed incorrectly.");
554 <<
"Destroying memory handler while " << arg1
555 <<
" objects are still allocated.");
561 "An input/output error has occurred. There are a number of " 562 "reasons why this may be happening, both for reading and " 563 "writing operations." 565 "If this happens during an operation that tries to read " 566 "data: First, you may be " 567 "trying to read from a file that doesn't exist or that is " 568 "not readable given its file permissions. Second, deal.II " 569 "uses this error at times if it tries to " 570 "read information from a file but where the information " 571 "in the file does not correspond to the expected format. " 572 "An example would be a truncated file, or a mesh file " 573 "that contains not only sections that describe the " 574 "vertices and cells, but also sections for additional " 575 "data that deal.II does not understand." 577 "If this happens during an operation that tries to write " 578 "data: you may be trying to write to a file to which file " 579 "or directory permissions do not allow you to write. A " 580 "typical example is where you specify an output file in " 581 "a directory that does not exist.");
591 <<
"Could not open file " << arg1 <<
".");
602 "You are trying to use functionality in deal.II that is " 603 "currently not implemented. In many cases, this indicates " 604 "that there simply didn't appear much of a need for it, or " 605 "that the author of the original code did not have the " 606 "time to implement a particular case. If you hit this " 607 "exception, it is therefore worth the time to look into " 608 "the code to find out whether you may be able to " 609 "implement the missing functionality. If you do, please " 610 "consider providing a patch to the deal.II development " 611 "sources (see the deal.II website on how to contribute).");
634 "This exception -- which is used in many places in the " 635 "library -- usually indicates that some condition which " 636 "the author of the code thought must be satisfied at a " 637 "certain point in an algorithm, is not fulfilled. An " 638 "example would be that the first part of an algorithm " 639 "sorts elements of an array in ascending order, and " 640 "a second part of the algorithm later encounters an " 641 "element that is not larger than the previous one." 643 "There is usually not very much you can do if you " 644 "encounter such an exception since it indicates an error " 645 "in deal.II, not in your own program. Try to come up with " 646 "the smallest possible program that still demonstrates " 647 "the error and contact the deal.II mailing lists with it " 658 "You (or a place in the library) are trying to call a " 659 "function that is declared as a virtual function in a " 660 "base class but that has not been overridden in your " 663 "This exception happens in cases where the base class " 664 "cannot provide a useful default implementation for " 665 "the virtual function, but where we also do not want " 666 "to mark the function as abstract (i.e., with '=0' at the end) " 667 "because the function is not essential to the class in many " 668 "contexts. In cases like this, the base class provides " 669 "a dummy implementation that makes the compiler happy, but " 670 "that then throws the current exception." 672 "A concrete example would be the 'Function' class. It declares " 673 "the existence of 'value()' and 'gradient()' member functions, " 674 "and both are marked as 'virtual'. Derived classes have to " 675 "override these functions for the values and gradients of a " 676 "particular function. On the other hand, not every function " 677 "has a gradient, and even for those that do, not every program " 678 "actually needs to evaluate it. Consequently, there is no " 679 "*requirement* that a derived class actually override the " 680 "'gradient()' function (as there would be had it been marked " 681 "as abstract). But, since the base class cannot know how to " 682 "compute the gradient, if a derived class does not override " 683 "the 'gradient()' function and it is called anyway, then the " 684 "default implementation in the base class will simply throw " 687 "The exception you see is what happens in cases such as the " 688 "one just illustrated. To fix the problem, you need to " 689 "investigate whether the function being called should indeed have " 690 "been called; if the answer is 'yes', then you need to " 691 "implement the missing override in your class.");
711 <<
"You are trying to execute functionality that is " 712 <<
"impossible in " << arg1
713 <<
"d or simply does not make any sense.");
725 <<
"You are trying to execute functionality that is " 726 <<
"impossible in dimensions <" << arg1 <<
"," << arg2
727 <<
"> or simply does not make any sense.");
734 "In a check in the code, deal.II encountered a zero in " 735 "a place where this does not make sense. See the condition " 736 "that was being checked and that is printed further up " 737 "in the error message to get more information on what " 738 "the erroneous zero corresponds to.");
745 "The object you are trying to access is empty but it makes " 746 "no sense to attempt the operation you are trying on an " 759 <<
"Dimension " << arg1 <<
" not equal to " << arg2 <<
".");
769 <<
"Dimension " << arg1 <<
" neither equal to " << arg2
770 <<
" nor to " << arg3 <<
".");
789 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 792 " In the current case, this half-open range is in fact empty, " 793 "suggesting that you are accessing an element of an empty " 794 "collection such as a vector that has not been set to the " 813 template <
typename T>
819 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 822 " In the current case, this half-open range is in fact empty, " 823 "suggesting that you are accessing an element of an empty " 824 "collection such as a vector that has not been set to the " 834 <<
"Number " << arg1 <<
" must be larger than or equal " 840 template <
typename T>
844 <<
"Number " << arg1 <<
" must be larger than or equal " 854 <<
"Division " << arg1 <<
" by " << arg2
855 <<
" has remainder different from zero.");
866 "You are trying to use an iterator, but the iterator is " 867 "in an invalid state. This may indicate that the iterator " 868 "object has not been initialized, or that it has been " 869 "moved beyond the end of the range of valid elements.");
876 "You are trying to use an iterator, but the iterator is " 877 "pointing past the end of the range of valid elements. " 878 "It is not valid to dereference the iterator in this " 900 "You are trying an operation on a vector that is only " 901 "allowed if the vector has no ghost elements, but the " 902 "vector you are operating on does have ghost elements. " 903 "Specifically, vectors with ghost elements are read-only " 904 "and cannot appear in operations that write into these " 907 "See the glossary entry on 'Ghosted vectors' for more " 918 "You are trying an operation of the form 'vector=s' with " 919 "a nonzero scalar value 's'. However, such assignments " 920 "are only allowed if the right hand side is zero.");
927 "You are attempting to use functionality that is only available " 928 "if deal.II was configured to use LAPACK, but cmake did not " 929 "find a valid LAPACK library.");
936 "You are attempting to use functionality that is only available " 937 "if deal.II was configured to use NetCDF, but cmake did not " 938 "find a valid NetCDF library.");
945 "You are attempting to use functionality that is only available " 946 "if deal.II was configured to use the function parser which " 947 "relies on the muparser library, but cmake did not " 948 "find a valid muparser library on your system and also did " 949 "not choose the one that comes bundled with deal.II.");
956 "You are attempting to use functionality that is only available " 957 "if deal.II was configured to use Assimp, but cmake did not " 958 "find a valid Assimp library.");
960 #ifdef DEAL_II_WITH_CUDA 973 <<
"There was an error in a cuSPARSE function: " << arg1);
977 #ifdef DEAL_II_WITH_MPI 1003 ExcMPI(
const int error_code);
1006 print_info(std::ostream &out)
const override;
1008 const int error_code;
1010 #endif // DEAL_II_WITH_MPI 1130 template <
class ExceptionType>
1135 const char *
function,
1137 const char * exc_name,
1140 e.set_fields(file, line,
function, cond, exc_name);
1145 ::deal_II_exceptions::internals::abort(e);
1170 template <
class ExceptionType>
1175 const char *
function,
1177 const char * exc_name,
1178 ExceptionType e) noexcept
1180 static_assert(std::is_base_of<ExceptionBase, ExceptionType>::value,
1181 "The provided exception must inherit from ExceptionBase.");
1188 #ifdef DEAL_II_WITH_CUDA 1226 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1227 # define Assert(cond, exc) \ 1229 if (__builtin_expect(!(cond), false)) \ 1230 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1231 ::deal_II_exceptions::internals::abort_on_exception, \ 1234 __PRETTY_FUNCTION__, \ 1240 # define Assert(cond, exc) \ 1243 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1244 ::deal_II_exceptions::internals::abort_on_exception, \ 1247 __PRETTY_FUNCTION__, \ 1254 # define Assert(cond, exc) \ 1277 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1278 # define AssertNothrow(cond, exc) \ 1280 if (__builtin_expect(!(cond), false)) \ 1281 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1282 ::deal_II_exceptions::internals:: \ 1283 abort_nothrow_on_exception, \ 1286 __PRETTY_FUNCTION__, \ 1292 # define AssertNothrow(cond, exc) \ 1295 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1296 ::deal_II_exceptions::internals:: \ 1297 abort_nothrow_on_exception, \ 1300 __PRETTY_FUNCTION__, \ 1307 # define AssertNothrow(cond, exc) \ 1328 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1329 # define AssertThrow(cond, exc) \ 1331 if (__builtin_expect(!(cond), false)) \ 1332 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1333 ::deal_II_exceptions::internals::throw_on_exception, \ 1336 __PRETTY_FUNCTION__, \ 1342 # define AssertThrow(cond, exc) \ 1345 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1346 ::deal_II_exceptions::internals::throw_on_exception, \ 1349 __PRETTY_FUNCTION__, \ 1366 #define AssertDimension(dim1, dim2) \ 1367 Assert((dim1) == (dim2), ::ExcDimensionMismatch((dim1), (dim2))) 1377 #define AssertVectorVectorDimension(vec, dim1, dim2) \ 1378 AssertDimension((vec).size(), (dim1)); \ 1379 for (unsigned int i = 0; i < dim1; ++i) \ 1381 AssertDimension((vec)[i].size(), (dim2)); \ 1389 template <
typename T>
1390 struct argument_type;
1391 template <
typename T,
typename U>
1392 struct argument_type<T(U)>
1407 #define AssertIndexRange(index, range) \ 1409 static_cast<typename ::internal::argument_type<void( \ 1410 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1412 static_cast<typename ::internal::argument_type<void( \ 1413 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1415 ExcIndexRangeType<typename ::internal::argument_type<void( \ 1416 typename std::common_type<decltype(index), decltype(range)>::type)>:: \ 1417 type>((index), 0, (range))) 1428 #define AssertIsFinite(number) \ 1429 Assert(::numbers::is_finite(number), \ 1430 ::ExcNumberNotFinite(std::complex<double>(number))) 1432 #ifdef DEAL_II_WITH_MPI 1443 # define AssertThrowMPI(error_code) \ 1444 AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code)) 1446 # define AssertThrowMPI(error_code) \ 1448 #endif // DEAL_II_WITH_MPI 1450 #ifdef DEAL_II_WITH_CUDA 1459 # define AssertCuda(error_code) \ 1460 Assert(error_code == cudaSuccess, \ 1461 ::ExcCudaError(cudaGetErrorString(error_code))) 1463 # define AssertCuda(error_code) \ 1465 (void)(error_code); \ 1477 # define AssertCusparse(error_code) \ 1479 error_code == CUSPARSE_STATUS_SUCCESS, \ 1481 deal_II_exceptions::internals::get_cusparse_error_string( \ 1484 # define AssertCusparse(error_code) \ 1486 (void)(error_code); \ 1491 # define AssertCusolver(error_code) \ 1493 error_code == CUSOLVER_STATUS_SUCCESS, \ 1495 deal_II_exceptions::internals::get_cusolver_error_string( \ 1498 # define AssertCusolver(error_code) \ 1500 (void)(error_code); \ 1508 DEAL_II_NAMESPACE_CLOSE
static::ExceptionBase & ExcCudaError(const char *arg1)
static::ExceptionBase & ExcPureFunctionCalled()
static::ExceptionBase & ExcNeedsFunctionparser()
void print_exc_data(std::ostream &out) const
#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)
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]
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)
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 generate_message() const
virtual void print_info(std::ostream &out) const
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)
static::ExceptionBase & ExcNeedsAssimp()
virtual ~ExceptionBase() noexceptoverride
virtual const char * what() const noexceptoverride
static::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
void print_stack_trace(std::ostream &out) const
static::ExceptionBase & ExcLowerRange(int arg1, int arg2)
void issue_error_nothrow(ExceptionHandling, const char *file, int line, const char *function, const char *cond, const char *exc_name, ExceptionType e) noexcept
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 abort(const ExceptionBase &exc)
static::ExceptionBase & ExcCusparseError(std::string arg1)
static::ExceptionBase & ExcEmptyObject()
static::ExceptionBase & ExcNotMultiple(int arg1, int arg2)
static::ExceptionBase & ExcNotImplemented()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
const char * get_exc_name() const
void disable_abort_on_exception()
static::ExceptionBase & ExcZero()
static::ExceptionBase & ExcFileNotOpen(std::string arg1)
static::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
static::ExceptionBase & ExcInternalError()