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> 32 DEAL_II_NAMESPACE_OPEN
82 const char *exc_name);
88 virtual const char *
what()
const noexcept;
104 virtual void print_info (std::ostream &out)
const;
126 const char *
function;
150 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 178 #define DeclException0(Exception0) \ 179 class Exception0 : public ::ExceptionBase {} 190 #define DeclExceptionMsg(Exception, defaulttext) \ 191 class Exception : public ::ExceptionBase \ 194 Exception (const std::string &msg = defaulttext) : arg (msg) {} \ 195 virtual ~Exception () noexcept {} \ 196 virtual void print_info (std::ostream &out) const { \ 197 out << " " << arg << std::endl; \ 200 const std::string arg; \ 209 #define DeclException1(Exception1, type1, outsequence) \ 210 class Exception1 : public ::ExceptionBase { \ 212 Exception1 (const type1 a1) : arg1 (a1) {} \ 213 virtual ~Exception1 () noexcept {} \ 214 virtual void print_info (std::ostream &out) const { \ 215 out << " " outsequence << std::endl; \ 228 #define DeclException2(Exception2, type1, type2, outsequence) \ 229 class Exception2 : public ::ExceptionBase { \ 231 Exception2 (const type1 a1, const type2 a2) : \ 232 arg1 (a1), arg2(a2) {} \ 233 virtual ~Exception2 () noexcept {} \ 234 virtual void print_info (std::ostream &out) const { \ 235 out << " " outsequence << std::endl; \ 249 #define DeclException3(Exception3, type1, type2, type3, outsequence) \ 250 class Exception3 : public ::ExceptionBase { \ 252 Exception3 (const type1 a1, const type2 a2, const type3 a3) : \ 253 arg1 (a1), arg2(a2), arg3(a3) {} \ 254 virtual ~Exception3 () noexcept {} \ 255 virtual void print_info (std::ostream &out) const { \ 256 out << " " outsequence << std::endl; \ 271 #define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 272 class Exception4 : public ::ExceptionBase { \ 274 Exception4 (const type1 a1, const type2 a2, \ 275 const type3 a3, const type4 a4) : \ 276 arg1 (a1), arg2(a2), arg3(a3), arg4(a4) {} \ 277 virtual ~Exception4 () noexcept {} \ 278 virtual void print_info (std::ostream &out) const { \ 279 out << " " outsequence << std::endl; \ 295 #define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence) \ 296 class Exception5 : public ::ExceptionBase { \ 298 Exception5 (const type1 a1, const type2 a2, const type3 a3, \ 299 const type4 a4, const type5 a5) : \ 300 arg1 (a1), arg2(a2), arg3(a3), arg4(a4), arg5(a5) {} \ 301 virtual ~Exception5 () noexcept {} \ 302 virtual void print_info (std::ostream &out) const { \ 303 out << " " outsequence << std::endl; \ 323 #define DeclException0(Exception0) \ 325 static ::ExceptionBase& Exception0 () 335 #define DeclExceptionMsg(Exception, defaulttext) \ 338 static ::ExceptionBase& Exception () 346 #define DeclException1(Exception1, type1, outsequence) \ 349 static ::ExceptionBase& Exception1 (type1 arg1) 358 #define DeclException2(Exception2, type1, type2, outsequence) \ 361 static ::ExceptionBase& Exception2 (type1 arg1, type2 arg2) 370 #define DeclException3(Exception3, type1, type2, type3, outsequence) \ 373 static ::ExceptionBase& Exception3 (type1 arg1, type2 arg2, type3 arg3) 382 #define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 385 static ::ExceptionBase& Exception4 (type1 arg1, type2 arg2, type3 arg3, type4 arg4) 394 #define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence) \ 397 static ::ExceptionBase& Exception5 (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 424 "A piece of code is attempting a division by zero. This is " 425 "likely going to lead to results that make no sense.");
438 std::complex<double>,
439 <<
"In a significant number of places, deal.II checks that some intermediate " 440 <<
"value is a finite number (as opposed to plus or minus infinity, or " 441 <<
"NaN/Not a Number). In the current function, we encountered a number " 442 <<
"that is not finite (its value is " << arg1 <<
" and therefore " 443 <<
"violates the current assertion).\n\n" 444 <<
"This may be due to the fact that some operation in this function " 445 <<
"created such a value, or because one of the arguments you passed " 446 <<
"to the function already had this value from some previous " 447 <<
"operation. In the latter case, this function only triggered the " 448 <<
"error but may not actually be responsible for the computation of " 449 <<
"the number that is not finite.\n\n" 450 <<
"There are two common cases where this situation happens. First, your " 451 <<
"code (or something in deal.II) divides by zero in a place where this " 452 <<
"should not happen. Or, you are trying to solve a linear system " 453 <<
"with an unsuitable solver (such as an indefinite or non-symmetric " 454 <<
"linear system using a Conjugate Gradient solver); such attempts " 455 <<
"oftentimes yield an operation somewhere that tries to divide " 456 <<
"by zero or take the square root of a negative value.\n\n" 457 <<
"In any case, when trying to find the source of the error, " 458 <<
"recall that the location where you are getting this error is " 459 <<
"simply the first place in the program where there is a check " 460 <<
"that a number (e.g., an element of a solution vector) is in fact " 461 <<
"finite, but that the actual error that computed the number " 462 <<
"may have happened far earlier. To find this location, you " 463 <<
"may want to add checks for finiteness in places of your " 464 <<
"program visited before the place where this error is produced." 465 <<
"One way to check for finiteness is to use the 'AssertIsFinite' " 472 "Your program tried to allocate some memory but this " 473 "allocation failed. Typically, this either means that " 474 "you simply do not have enough memory in your system, " 475 "or that you are (erroneously) trying to allocate " 476 "a chunk of memory that is simply beyond all reasonable " 477 "size, for example because the size of the object has " 478 "been computed incorrectly.");
485 <<
"Destroying memory handler while " << arg1
486 <<
" objects are still allocated.");
492 "An input/output error has occurred. There are a number of " 493 "reasons why this may be happening, both for reading and " 494 "writing operations." 496 "If this happens during an operation that tries to read " 497 "data: First, you may be " 498 "trying to read from a file that doesn't exist or that is " 499 "not readable given its file permissions. Second, deal.II " 500 "uses this error at times if it tries to " 501 "read information from a file but where the information " 502 "in the file does not correspond to the expected format. " 503 "An example would be a truncated file, or a mesh file " 504 "that contains not only sections that describe the " 505 "vertices and cells, but also sections for additional " 506 "data that deal.II does not understand." 508 "If this happens during an operation that tries to write " 509 "data: you may be trying to write to a file to which file " 510 "or directory permissions do not allow you to write. A " 511 "typical example is where you specify an output file in " 512 "a directory that does not exist.");
522 <<
"Could not open file " << arg1 <<
".");
533 "You are trying to use functionality in deal.II that is " 534 "currently not implemented. In many cases, this indicates " 535 "that there simply didn't appear much of a need for it, or " 536 "that the author of the original code did not have the " 537 "time to implement a particular case. If you hit this " 538 "exception, it is therefore worth the time to look into " 539 "the code to find out whether you may be able to " 540 "implement the missing functionality. If you do, please " 541 "consider providing a patch to the deal.II development " 542 "sources (see the deal.II website on how to contribute).");
565 "This exception -- which is used in many places in the " 566 "library -- usually indicates that some condition which " 567 "the author of the code thought must be satisfied at a " 568 "certain point in an algorithm, is not fulfilled. An " 569 "example would be that the first part of an algorithm " 570 "sorts elements of an array in ascending order, and " 571 "a second part of the algorithm later encounters an " 572 "element that is not larger than the previous one." 574 "There is usually not very much you can do if you " 575 "encounter such an exception since it indicates an error " 576 "in deal.II, not in your own program. Try to come up with " 577 "the smallest possible program that still demonstrates " 578 "the error and contact the deal.II mailing lists with it " 588 "You (or a place in the library) are trying to call a " 589 "function that is declared as a virtual function in a " 590 "base class but that has not been overridden in your " 593 "This exception happens in cases where the base class " 594 "cannot provide a useful default implementation for " 595 "the virtual function, but where we also do not want " 596 "to mark the function as abstract (i.e., with '=0' at the end) " 597 "because the function is not essential to the class in many " 598 "contexts. In cases like this, the base class provides " 599 "a dummy implementation that makes the compiler happy, but " 600 "that then throws the current exception." 602 "A concrete example would be the 'Function' class. It declares " 603 "the existence of 'value()' and 'gradient()' member functions, " 604 "and both are marked as 'virtual'. Derived classes have to " 605 "override these functions for the values and gradients of a " 606 "particular function. On the other hand, not every function " 607 "has a gradient, and even for those that do, not every program " 608 "actually needs to evaluate it. Consequently, there is no " 609 "*requirement* that a derived class actually override the " 610 "'gradient()' function (as there would be had it been marked " 611 "as abstract). But, since the base class cannot know how to " 612 "compute the gradient, if a derived class does not override " 613 "the 'gradient()' function and it is called anyway, then the " 614 "default implementation in the base class will simply throw " 617 "The exception you see is what happens in cases such as the " 618 "one just illustrated. To fix the problem, you need to " 619 "investigate whether the function being called should indeed have " 620 "been called; if the answer is 'yes', then you need to " 621 "implement the missing override in your class.");
641 <<
"You are trying to execute functionality that is " 642 <<
"impossible in " << arg1
643 <<
"d or simply does not make any sense.");
654 <<
"You are trying to execute functionality that is " 655 <<
"impossible in dimensions <" << arg1 <<
"," << arg2
656 <<
"> or simply does not make any sense.");
663 "In a check in the code, deal.II encountered a zero in " 664 "a place where this does not make sense. See the condition " 665 "that was being checked and that is printed further up " 666 "in the error message to get more information on what " 667 "the erroneous zero corresponds to.");
674 "The object you are trying to access is empty but it makes " 675 "no sense to attempt the operation you are trying on an " 686 std::size_t, std::size_t,
687 <<
"Dimension " << arg1 <<
" not equal to " << arg2 <<
".");
695 <<
"Dimension " << arg1 <<
" neither equal to " << arg2
696 <<
" nor to " << arg3 <<
".");
712 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 715 " In the current case, this half-open range is in fact empty, " 716 "suggesting that you are accessing an element of an empty " 717 "collection such as a vector that has not been set to the " 737 template <
typename T>
740 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 743 " In the current case, this half-open range is in fact empty, " 744 "suggesting that you are accessing an element of an empty " 745 "collection such as a vector that has not been set to the " 755 <<
"Number " << arg1 <<
" must be larger than or equal " 761 template <
typename T>
764 <<
"Number " << arg1 <<
" must be larger than or equal " 773 <<
"Division " << arg1 <<
" by " << arg2
774 <<
" has remainder different from zero.");
785 "You are trying to use an iterator, but the iterator is " 786 "in an invalid state. This may indicate that the iterator " 787 "object has not been initialized, or that it has been " 788 "moved beyond the end of the range of valid elements.");
795 "You are trying to use an iterator, but the iterator is " 796 "pointing past the end of the range of valid elements. " 797 "It is not valid to dereference the iterator in this " 821 "You are trying an operation on a vector that is only " 822 "allowed if the vector has no ghost elements, but the " 823 "vector you are operating on does have ghost elements. " 824 "Specifically, vectors with ghost elements are read-only " 825 "and cannot appear in operations that write into these " 828 "See the glossary entry on 'Ghosted vectors' for more " 839 "You are trying an operation of the form 'vector=s' with " 840 "a nonzero scalar value 's'. However, such assignments " 841 "are only allowed if the right hand side is zero.");
847 "You are attempting to use functionality that is only available " 848 "if deal.II was configured to use LAPACK, but cmake did not " 849 "find a valid LAPACK library.");
855 "You are attempting to use functionality that is only available " 856 "if deal.II was configured to use NetCDF, but cmake did not " 857 "find a valid NetCDF library.");
863 "You are attempting to use functionality that is only available " 864 "if deal.II was configured to use the function parser which " 865 "relies on the muparser library, but cmake did not " 866 "find a valid muparser library on your system and also did " 867 "not choose the one that comes bundled with deal.II.");
873 "You are attempting to use functionality that is only available " 874 "if deal.II was configured to use Assimp, but cmake did not " 875 "find a valid Assimp library.");
877 #ifdef DEAL_II_WITH_CUDA 892 <<
"There was an error in a cuSPARSE function: " 897 #ifdef DEAL_II_WITH_MPI 923 ExcMPI (
const int error_code);
925 virtual void print_info (std::ostream &out)
const;
927 const int error_code;
929 #endif // DEAL_II_WITH_MPI 1048 template <
class ExceptionType>
1053 const char *
function,
1055 const char *exc_name,
1059 e.set_fields (file, line,
function, cond, exc_name);
1064 ::deal_II_exceptions::internals::abort(e);
1090 template <
class ExceptionType>
1094 const char *
function,
1096 const char *exc_name,
1097 ExceptionType e) noexcept
1099 static_assert(std::is_base_of<ExceptionBase, ExceptionType>::value,
1100 "The provided exception must inherit from ExceptionBase.");
1102 e.set_fields (file, line,
function, cond, exc_name);
1107 #ifdef DEAL_II_WITH_CUDA 1141 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1142 # define Assert(cond, exc) \ 1144 if (__builtin_expect(!(cond), false)) \ 1145 ::deal_II_exceptions::internals:: issue_error_noreturn( \ 1146 ::deal_II_exceptions::internals::abort_on_exception, \ 1147 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1150 # define Assert(cond, exc) \ 1153 ::deal_II_exceptions::internals:: issue_error_noreturn( \ 1154 ::deal_II_exceptions::internals::abort_on_exception, \ 1155 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1159 #define Assert(cond, exc) \ 1182 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1183 # define AssertNothrow(cond, exc) \ 1185 if (__builtin_expect(!(cond), false)) \ 1186 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1187 ::deal_II_exceptions::internals::abort_nothrow_on_exception, \ 1188 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1191 # define AssertNothrow(cond, exc) \ 1194 ::deal_II_exceptions::internals::issue_error_nothrow( \ 1195 ::deal_II_exceptions::internals::abort_nothrow_on_exception, \ 1196 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1200 #define AssertNothrow(cond, exc) \ 1220 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT 1221 #define AssertThrow(cond, exc) \ 1223 if (__builtin_expect(!(cond), false)) \ 1224 ::deal_II_exceptions::internals:: issue_error_noreturn( \ 1225 ::deal_II_exceptions::internals::throw_on_exception, \ 1226 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1229 #define AssertThrow(cond, exc) \ 1232 ::deal_II_exceptions::internals::issue_error_noreturn( \ 1233 ::deal_II_exceptions::internals::throw_on_exception, \ 1234 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 1248 #define AssertDimension(dim1,dim2) \ 1249 Assert((dim1) == (dim2), ::ExcDimensionMismatch((dim1),(dim2))) 1259 #define AssertVectorVectorDimension(vec,dim1,dim2) \ 1260 AssertDimension((vec).size(), (dim1)); \ 1261 for (unsigned int i=0;i<dim1;++i) {AssertDimension((vec)[i].size(), (dim2));} 1268 template<
typename T>
struct argument_type;
1269 template<
typename T,
typename U>
struct argument_type<T(U)>
1284 #define AssertIndexRange(index,range) \ 1285 Assert((index) < (range), \ 1286 ExcIndexRangeType<typename ::internal::argument_type< \ 1287 void(typename std::common_type<decltype(index), \ 1288 decltype(range)>::type)>::type>((index),0,(range))) 1299 #define AssertIsFinite(number) \ 1300 Assert(::numbers::is_finite(number), \ 1301 ::ExcNumberNotFinite(std::complex<double>(number))) 1303 #ifdef DEAL_II_WITH_MPI 1314 #define AssertThrowMPI(error_code) \ 1315 AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code)) 1317 #define AssertThrowMPI(error_code) {} 1318 #endif // DEAL_II_WITH_MPI 1320 #ifdef DEAL_II_WITH_CUDA 1329 #define AssertCuda(error_code) Assert(error_code == cudaSuccess, \ 1330 ::ExcCudaError(cudaGetErrorString(error_code))) 1332 #define AssertCuda(error_code) { (void) (error_code); } 1343 #define AssertCusparse(error_code) Assert(error_code == CUSPARSE_STATUS_SUCCESS, \ 1345 deal_II_exceptions::internals:: \ 1346 get_cusparse_error_string(error_code))) 1348 #define AssertCusparse(error_code) { (void) (error_code); } 1352 #define AssertCusolver(error_code) Assert(error_code == CUSOLVER_STATUS_SUCCESS, \ 1354 deal_II_exceptions::internals:: \ 1355 get_cusolver_error_string(error_code))) 1357 #define AssertCusolver(error_code) { (void) (error_code); } 1364 DEAL_II_NAMESPACE_CLOSE
virtual void print_info(std::ostream &out) const
virtual const char * what() const noexcept
static ::ExceptionBase & ExcPureFunctionCalled()
static ::ExceptionBase & ExcNeedsFunctionparser()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcFileNotOpen(char *arg1)
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]
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)
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)
static ::ExceptionBase & ExcNeedsAssimp()
static ::ExceptionBase & ExcCudaError(char *arg1)
static ::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
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
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 abort(const ExceptionBase &exc)
static ::ExceptionBase & ExcCusparseError(std::string arg1)
static ::ExceptionBase & ExcEmptyObject()
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
virtual ~ExceptionBase() noexcept
void disable_abort_on_exception()
const char * get_exc_name() const
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
static ::ExceptionBase & ExcInternalError()