16 #ifndef dealii__exceptions_h 17 #define dealii__exceptions_h 19 #include <deal.II/base/config.h> 25 DEAL_II_NAMESPACE_OPEN
69 const char *exc_name);
75 virtual const char *
what()
const throw();
91 virtual void print_info (std::ostream &out)
const;
113 const char *
function;
137 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 141 void *raw_stacktrace[25];
242 abort_nothrow_on_exception
255 const char *
function,
257 const char *exc_name,
261 e.set_fields (file, line,
function, cond, exc_name);
265 case abort_on_exception:
266 ::deal_II_exceptions::internals::abort(e);
268 case abort_nothrow_on_exception:
269 ::deal_II_exceptions::internals::abort(e,
true);
271 case throw_on_exception:
294 #define Assert(cond, exc) \ 297 ::deal_II_exceptions::internals:: \ 298 issue_error(::deal_II_exceptions::internals::abort_on_exception,\ 299 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 302 #define Assert(cond, exc) \ 323 #define AssertNothrow(cond, exc) \ 326 ::deal_II_exceptions::internals:: \ 328 ::deal_II_exceptions::internals::abort_nothrow_on_exception, \ 329 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 332 #define AssertNothrow(cond, exc) \ 349 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT 350 #define AssertThrow(cond, exc) \ 352 if (__builtin_expect(!(cond), false)) \ 353 ::deal_II_exceptions::internals:: \ 354 issue_error(::deal_II_exceptions::internals::throw_on_exception,\ 355 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 358 #define AssertThrow(cond, exc) \ 361 ::deal_II_exceptions::internals:: \ 362 issue_error(::deal_II_exceptions::internals::throw_on_exception,\ 363 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ 377 #define DeclException0(Exception0) \ 378 class Exception0 : public ::ExceptionBase {} 389 #define DeclExceptionMsg(Exception, defaulttext) \ 390 class Exception : public ::ExceptionBase \ 393 Exception (const std::string &msg = defaulttext) : arg (msg) {} \ 394 virtual ~Exception () throw () {} \ 395 virtual void print_info (std::ostream &out) const { \ 396 out << arg << std::endl; \ 399 const std::string arg; \ 408 #define DeclException1(Exception1, type1, outsequence) \ 409 class Exception1 : public ::ExceptionBase { \ 411 Exception1 (const type1 a1) : arg1 (a1) {} \ 412 virtual ~Exception1 () throw () {} \ 413 virtual void print_info (std::ostream &out) const { \ 414 out outsequence << std::endl; \ 427 #define DeclException2(Exception2, type1, type2, outsequence) \ 428 class Exception2 : public ::ExceptionBase { \ 430 Exception2 (const type1 a1, const type2 a2) : \ 431 arg1 (a1), arg2(a2) {} \ 432 virtual ~Exception2 () throw () {} \ 433 virtual void print_info (std::ostream &out) const { \ 434 out outsequence << std::endl; \ 448 #define DeclException3(Exception3, type1, type2, type3, outsequence) \ 449 class Exception3 : public ::ExceptionBase { \ 451 Exception3 (const type1 a1, const type2 a2, const type3 a3) : \ 452 arg1 (a1), arg2(a2), arg3(a3) {} \ 453 virtual ~Exception3 () throw () {} \ 454 virtual void print_info (std::ostream &out) const { \ 455 out outsequence << std::endl; \ 470 #define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 471 class Exception4 : public ::ExceptionBase { \ 473 Exception4 (const type1 a1, const type2 a2, \ 474 const type3 a3, const type4 a4) : \ 475 arg1 (a1), arg2(a2), arg3(a3), arg4(a4) {} \ 476 virtual ~Exception4 () throw () {} \ 477 virtual void print_info (std::ostream &out) const { \ 478 out outsequence << std::endl; \ 494 #define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence) \ 495 class Exception5 : public ::ExceptionBase { \ 497 Exception5 (const type1 a1, const type2 a2, const type3 a3, \ 498 const type4 a4, const type5 a5) : \ 499 arg1 (a1), arg2(a2), arg3(a3), arg4(a4), arg5(a5) {} \ 500 virtual ~Exception5 () throw () {} \ 501 virtual void print_info (std::ostream &out) const { \ 502 out outsequence << std::endl; \ 522 #define DeclException0(Exception0) \ 523 static ::ExceptionBase& Exception0 () 533 #define DeclExceptionMsg(Exception, defaulttext) \ 534 static ::ExceptionBase& Exception () 542 #define DeclException1(Exception1, type1, outsequence) \ 543 static ::ExceptionBase& Exception1 (type1 arg1) throw (errortext outsequence) 552 #define DeclException2(Exception2, type1, type2, outsequence) \ 553 static ::ExceptionBase& Exception2 (type1 arg1, type2 arg2) throw (errortext outsequence) 562 #define DeclException3(Exception3, type1, type2, type3, outsequence) \ 563 static ::ExceptionBase& Exception3 (type1 arg1, type2 arg2, type3 arg3) throw (errortext outsequence) 572 #define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \ 573 static ::ExceptionBase& Exception4 (type1 arg1, type2 arg2, type3 arg3, type4 arg4) throw (errortext outsequence) 582 #define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence) \ 583 static ::ExceptionBase& Exception5 (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) throw (errortext outsequence) 610 "A piece of code is attempting a division by zero. This is " 611 "likely going to lead to results that make no sense.");
624 std::complex<double>,
625 <<
"In a significant number of places, deal.II checks that some intermediate " 626 <<
"value is a finite number (as opposed to plus or minus infinity, or " 627 <<
"NaN/Not a Number). In the current function, we encountered a number " 628 <<
"that is not finite (its value is " << arg1 <<
" and therefore " 629 <<
"violates the current assertion.\n\n" 630 <<
"This may be due to the fact that some operation in this function " 631 <<
"created such a value, or because one of the arguments you passed " 632 <<
"to the function already had this value from some previous " 633 <<
"operation. In the latter case, this function only triggered the " 634 <<
"error but may not actually be responsible for the computation of " 635 <<
"the number that is not finite.\n\n" 636 <<
"There are two common cases where this situation happens. First, your " 637 <<
"code (or something in deal.II) divides by zero in a place where this " 638 <<
"should not happen. Or, you are trying to solve a linear system " 639 <<
"with an unsuitable solver (such as an indefinite or non-symmetric " 640 <<
"linear system using a Conjugate Gradient solver); such attempts " 641 <<
"oftentimes yield an operation somewhere that tries to divide " 642 <<
"by zero or take the square root of a negative value.\n\n" 643 <<
"In any case, when trying to find the source of the error, " 644 <<
"recall that the location where you are getting this error is " 645 <<
"simply the first place in the program where there is a check " 646 <<
"that a number (e.g., an element of a solution vector) is in fact " 647 <<
"finite, but that the actual error that computed the number " 648 <<
"may have happened far earlier. To find this location, you " 649 <<
"may want to add checks for finiteness in places of your " 650 <<
"program visited before the place where this error is produced." 651 <<
"One way to check for finiteness is to use the 'AssertIsFinite' " 658 "Your program tried to allocate some memory but this " 659 "allocation failed. Typically, this either means that " 660 "you simply do not have enough memory in your system, " 661 "or that you are (erroneously) trying to allocate " 662 "a chunk of memory that is simply beyond all reasonable " 663 "size, for example because the size of the object has " 664 "been computed incorrectly.");
671 <<
"Destroying memory handler while " << arg1
672 <<
" objects are still allocated");
678 "An input/output error has occurred. There are a number of " 679 "reasons why this may be happening, both for reading and " 680 "writing operations." 682 "If this happens during an operation that tries to read " 683 "data: First, you may be " 684 "trying to read from a file that doesn't exist or that is " 685 "not readable given its file permissions. Second, deal.II " 686 "uses this error at times if it tries to " 687 "read information from a file but where the information " 688 "in the file does not correspond to the expected format. " 689 "An example would be a truncated file, or a mesh file " 690 "that contains not only sections that describe the " 691 "vertices and cells, but also sections for additional " 692 "data that deal.II does not understand." 694 "If this happens during an operation that tries to write " 695 "data: you may be trying to write to a file to which file " 696 "or directory permissions do not allow you to write. A " 697 "typical example is where you specify an output file in " 698 "a directory that does not exist.");
708 <<
"Could not open file " << arg1);
719 "You are trying to use functionality in deal.II that is " 720 "currently not implemented. In many cases, this indicates " 721 "that there simply didn't appear much of a need for it, or " 722 "that the author of the original code did not have the " 723 "time to implement a particular case. If you hit this " 724 "exception, it is therefore worth the time to look into " 725 "the code to find out whether you may be able to " 726 "implement the missing functionality. If you do, please " 727 "consider providing a patch to the deal.II development " 728 "sources (see the deal.II website on how to contribute).");
751 "This exception -- which is used in many places in the " 752 "library -- usually indicates that some condition which " 753 "the author of the code thought must be satisfied at a " 754 "certain point in an algorithm, is not fulfilled. An " 755 "example would be that the first part of an algorithm " 756 "sorts elements of an array in ascending order, and " 757 "a second part of the algorithm later encounters an " 758 "an element that is not larger than the previous one." 760 "There is usually not very much you can do if you " 761 "encounter such an exception since it indicates an error " 762 "in deal.II, not in your own program. Try to come up with " 763 "the smallest possible program that still demonstrates " 764 "the error and contact the deal.II mailing lists with it " 774 "You (or a place in the library) are trying to call a " 775 "function that is declared as a virtual function in a " 776 "base class but that has not been overridden in your " 779 "This exception happens in cases where the base class " 780 "cannot provide a useful default implementation for " 781 "the virtual function, but where we also do not want " 782 "to mark the function as abstract (i.e., with '=0' at the end) " 783 "because the function is not essential to the class in many " 784 "contexts. In cases like this, the base class provides " 785 "a dummy implementation that makes the compiler happy, but " 786 "that then throws the current exception." 788 "A concrete example would be the 'Function' class. It declares " 789 "the existence of 'value()' and 'gradient()' member functions, " 790 "and both are marked as 'virtual'. Derived classes have to " 791 "override these functions for the values and gradients of a " 792 "particular function. On the other hand, not every function " 793 "has a gradient, and even for those that do, not every program " 794 "actually needs to evaluate it. Consequently, there is no " 795 "*requirement* that a derived class actually override the " 796 "'gradient()' function (as there would be had it been marked " 797 "as abstract). But, since the base class cannot know how to " 798 "compute the gradient, if a derived class does not override " 799 "the 'gradient()' function and it is called anyway, then the " 800 "default implementation in the base class will simply throw " 803 "The exception you see is what happens in cases such as the " 804 "one just illustrated. To fix the problem, you need to " 805 "investigate whether the function being called should indeed have " 806 "been called; if the answer is 'yes', then you need to " 807 "implement the missing override in your class.");
834 <<
"You are trying to execute functionality that is " 835 <<
"impossible in " << arg1
836 <<
"d or simply does not make any sense.");
842 "In a check in the code, deal.II encountered a zero in " 843 "a place where this does not make sense. See the condition " 844 "that was being checked and that is printed further up " 845 "in the error message to get more information on what " 846 "the erroneous zero corresponds to.");
853 "The object you are trying to access is empty but it makes " 854 "no sense to attempt the operation you are trying on an " 865 std::size_t, std::size_t,
866 <<
"Dimension " << arg1 <<
" not equal to " << arg2);
874 <<
"Dimension " << arg1 <<
" neither equal to " << arg2
875 <<
" nor to " << arg3);
891 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 894 " In the current case, this half-open range is in fact empty, " 895 "suggesting that you are accessing an element of an empty " 896 "collection such as a vector that has not been set to the " 916 template <
typename T>
919 <<
"Index " << arg1 <<
" is not in the half-open range [" << arg2 <<
"," 922 " In the current case, this half-open range is in fact empty, " 923 "suggesting that you are accessing an element of an empty " 924 "collection such as a vector that has not been set to the " 934 <<
"Number " << arg1 <<
" must be larger than or equal " 940 template <
typename T>
943 <<
"Number " << arg1 <<
" must be larger than or equal " 952 <<
"Division " << arg1 <<
" by " << arg2
953 <<
" has remainder different from zero");
964 "You are trying to use an iterator, but the iterator is " 965 "in an invalid state. This may indicate that the iterator " 966 "object has not been initialized, or that it has been " 967 "moved beyond the end of the range of valid elements.");
974 "You are trying to use an iterator, but the iterator is " 975 "pointing past the end of the range of valid elements. " 976 "It is not valid to dereference the iterator in this " 1000 "You are trying an operation on a vector that is only " 1001 "allowed if the vector has no ghost elements, but the " 1002 "vector you are operating on does have ghost elements. " 1003 "Specifically, vectors with ghost elements are read-only " 1004 "and cannot appear in operations that write into these " 1007 "See the glossary entry on 'Ghosted vectors' for more " 1018 "You are trying an operation of the form 'vector=s' with " 1019 "a nonzero scalar value 's'. However, such assignments " 1020 "are only allowed if the right hand side is zero.");
1052 #define AssertDimension(dim1,dim2) Assert((dim1) == (dim2), \ 1053 ::ExcDimensionMismatch((dim1),(dim2))) 1063 #define AssertVectorVectorDimension(vec,dim1,dim2) AssertDimension((vec).size(), (dim1)) \ 1064 for (unsigned int i=0;i<dim1;++i) { AssertDimension((vec)[i].size(), (dim2)); } 1081 #define AssertIndexRange(index,range) Assert((index) < (range), \ 1082 ::ExcIndexRange((index),0,(range))) 1084 #define AssertGlobalIndexRange(index,range) Assert((index) < (range), \ 1085 ExcIndexRange<types::global_dof_index>((index),0,(range))) 1096 #define AssertIsFinite(number) Assert(::numbers::is_finite(number), \ 1097 ExcNumberNotFinite(std::complex<double>(number))) 1101 DEAL_II_NAMESPACE_CLOSE
::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
void suppress_stacktrace_in_exceptions()
::ExceptionBase & ExcMessage(std::string arg1)
void set_additional_assert_output(const char *const p)
virtual void print_info(std::ostream &out) const
void abort(const ExceptionBase &exc, bool nothrow=false)
#define DeclException1(Exception1, type1, outsequence)
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
virtual const char * what() const
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException0(Exception0)
::ExceptionBase & ExcLowerRange(int arg1, int arg2)." )
::ExceptionBase & ExcNeedsFunctionparser()
::ExceptionBase & ExcNeedsNetCDF()
::ExceptionBase & ExcNeedsLAPACK()
void print_stack_trace(std::ostream &out) const
::ExceptionBase & ExcNumberNotFinite(std::complex< double > arg1)
::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)." << (arg2
::ExceptionBase & ExcNotMultiple(int arg1, int arg2)
void print_exc_data(std::ostream &out) const
#define DeclException3(Exception3, type1, type2, type3, outsequence)
void generate_message() const
void disable_abort_on_exception()
const char * get_exc_name() const
void issue_error(ExceptionHandling handling, const char *file, int line, const char *function, const char *cond, const char *exc_name, exc e)