Reference documentation for deal.II version Git 50c3491829 2021-08-01 13:40:40 +0200
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
exceptions.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2021 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_exceptions_h
17 #define dealii_exceptions_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <exception>
22 #include <ostream>
23 #include <string>
24 #include <type_traits>
25 
26 #ifdef DEAL_II_WITH_CUDA
27 # include <cusolverSp.h>
28 # include <cusparse.h>
29 #endif
30 
31 
33 
34 
48 class ExceptionBase : public std::exception
49 {
50 public:
54  ExceptionBase();
55 
60 
64  virtual ~ExceptionBase() noexcept override;
65 
71  operator=(const ExceptionBase &) = delete;
72 
78  void
79  set_fields(const char *file,
80  const int line,
81  const char *function,
82  const char *cond,
83  const char *exc_name);
84 
85 
89  virtual const char *
90  what() const noexcept override;
91 
95  const char *
96  get_exc_name() const;
97 
101  void
102  print_exc_data(std::ostream &out) const;
103 
108  virtual void
109  print_info(std::ostream &out) const;
110 
115  void
116  print_stack_trace(std::ostream &out) const;
117 
118 protected:
122  const char *file;
123 
127  unsigned int line;
128 
132  const char *function;
133 
137  const char *cond;
138 
142  const char *exc;
143 
148  mutable char **stacktrace;
149 
155 
156 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
157 
160  void *raw_stacktrace[25];
161 #endif
162 
163 private:
167  void
168  generate_message() const;
169 
174  mutable std::string what_str;
175 };
176 
177 #ifndef DOXYGEN
178 
195 # define DeclException0(Exception0) \
196  class Exception0 : public ::ExceptionBase \
197  {}
198 
199 
219 # define DeclExceptionMsg(Exception, defaulttext) \
220  class Exception : public ::ExceptionBase \
221  { \
222  public: \
223  Exception(const std::string &msg = defaulttext) \
224  : arg(msg) \
225  {} \
226  virtual ~Exception() noexcept \
227  {} \
228  virtual void \
229  print_info(std::ostream &out) const override \
230  { \
231  out << " " << arg << std::endl; \
232  } \
233  \
234  private: \
235  const std::string arg; \
236  }
237 
255 # define DeclException1(Exception1, type1, outsequence) \
256  class Exception1 : public ::ExceptionBase \
257  { \
258  public: \
259  Exception1(type1 const &a1) \
260  : arg1(a1) \
261  {} \
262  virtual ~Exception1() noexcept \
263  {} \
264  virtual void \
265  print_info(std::ostream &out) const override \
266  { \
267  out << " " outsequence << std::endl; \
268  } \
269  \
270  private: \
271  type1 const arg1; \
272  }
273 
274 
292 # define DeclException2(Exception2, type1, type2, outsequence) \
293  class Exception2 : public ::ExceptionBase \
294  { \
295  public: \
296  Exception2(type1 const &a1, type2 const &a2) \
297  : arg1(a1) \
298  , arg2(a2) \
299  {} \
300  virtual ~Exception2() noexcept \
301  {} \
302  virtual void \
303  print_info(std::ostream &out) const override \
304  { \
305  out << " " outsequence << std::endl; \
306  } \
307  \
308  private: \
309  type1 const arg1; \
310  type2 const arg2; \
311  }
312 
313 
331 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
332  class Exception3 : public ::ExceptionBase \
333  { \
334  public: \
335  Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \
336  : arg1(a1) \
337  , arg2(a2) \
338  , arg3(a3) \
339  {} \
340  virtual ~Exception3() noexcept \
341  {} \
342  virtual void \
343  print_info(std::ostream &out) const override \
344  { \
345  out << " " outsequence << std::endl; \
346  } \
347  \
348  private: \
349  type1 const arg1; \
350  type2 const arg2; \
351  type3 const arg3; \
352  }
353 
354 
372 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
373  class Exception4 : public ::ExceptionBase \
374  { \
375  public: \
376  Exception4(type1 const &a1, \
377  type2 const &a2, \
378  type3 const &a3, \
379  type4 const &a4) \
380  : arg1(a1) \
381  , arg2(a2) \
382  , arg3(a3) \
383  , arg4(a4) \
384  {} \
385  virtual ~Exception4() noexcept \
386  {} \
387  virtual void \
388  print_info(std::ostream &out) const override \
389  { \
390  out << " " outsequence << std::endl; \
391  } \
392  \
393  private: \
394  type1 const arg1; \
395  type2 const arg2; \
396  type3 const arg3; \
397  type4 const arg4; \
398  }
399 
400 
418 # define DeclException5( \
419  Exception5, type1, type2, type3, type4, type5, outsequence) \
420  class Exception5 : public ::ExceptionBase \
421  { \
422  public: \
423  Exception5(type1 const &a1, \
424  type2 const &a2, \
425  type3 const &a3, \
426  type4 const &a4, \
427  type5 const &a5) \
428  : arg1(a1) \
429  , arg2(a2) \
430  , arg3(a3) \
431  , arg4(a4) \
432  , arg5(a5) \
433  {} \
434  virtual ~Exception5() noexcept \
435  {} \
436  virtual void \
437  print_info(std::ostream &out) const override \
438  { \
439  out << " " outsequence << std::endl; \
440  } \
441  \
442  private: \
443  type1 const arg1; \
444  type2 const arg2; \
445  type3 const arg3; \
446  type4 const arg4; \
447  type5 const arg5; \
448  }
449 
450 #else /*ifndef DOXYGEN*/
451 
452 // Dummy definitions for doxygen:
453 
470 # define DeclException0(Exception0) \
471  \
472  static ::ExceptionBase &Exception0()
473 
493 # define DeclExceptionMsg(Exception, defaulttext) \
494  \
495  \
496  static ::ExceptionBase &Exception()
497 
515 # define DeclException1(Exception1, type1, outsequence) \
516  \
517  \
518  static ::ExceptionBase &Exception1(type1 arg1)
519 
520 
538 # define DeclException2(Exception2, type1, type2, outsequence) \
539  \
540  \
541  static ::ExceptionBase &Exception2(type1 arg1, type2 arg2)
542 
543 
561 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
562  \
563  \
564  static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3)
565 
566 
584 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
585  \
586  \
587  static ::ExceptionBase &Exception4(type1 arg1, \
588  type2 arg2, \
589  type3 arg3, \
590  type4 arg4)
591 
592 
610 # define DeclException5( \
611  Exception5, type1, type2, type3, type4, type5, outsequence) \
612  \
613  \
614  static ::ExceptionBase &Exception5( \
615  type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)
616 
617 #endif /*ifndef DOXYGEN*/
618 
619 
632 {
637 
642  "A piece of code is attempting a division by zero. This is "
643  "likely going to lead to results that make no sense.");
644 
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' "
685  << "macro.");
686 
691  std::size_t,
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."
699  "\n\n"
700  "In the current case, the request was for "
701  << arg1 << " bytes.");
702 
708  int,
709  << "Destroying memory handler while " << arg1
710  << " objects are still allocated.");
711 
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."
719  "\n\n"
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."
731  "\n\n"
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.");
737 
745  std::string,
746  << "Could not open file " << arg1
747  << "."
748  "\n\n"
749  "If this happens during an operation that tries to read "
750  "data: you may be "
751  "trying to read from a file that doesn't exist or that is "
752  "not readable given its file permissions."
753  "\n\n"
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.");
759 
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).");
779 
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."
809  "\n\n"
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 "
815  "to obtain help.");
816 
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 "
828  "derived class."
829  "\n\n"
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."
838  "\n\n"
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 "
852  "an exception."
853  "\n\n"
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.");
859 
864 
869 
877  int,
878  << "You are trying to execute functionality that is "
879  << "impossible in " << arg1
880  << "d or simply does not make any sense.");
881 
890  int,
891  int,
892  << "You are trying to execute functionality that is "
893  << "impossible in dimensions <" << arg1 << "," << arg2
894  << "> or simply does not make any sense.");
895 
896 
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.");
906 
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 "
914  "empty object.");
915 
924  std::size_t,
925  std::size_t,
926  << "Dimension " << arg1 << " not equal to " << arg2 << ".");
927 
933  int,
934  int,
935  int,
936  << "Dimension " << arg1 << " neither equal to " << arg2
937  << " nor to " << arg3 << ".");
938 
953  int,
954  int,
955  int,
956  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ","
957  << arg3 << ")."
958  << (arg2 == arg3 ?
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 "
962  "correct size." :
963  ""));
964 
980  template <typename T>
983  T,
984  T,
985  T,
986  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ","
987  << arg3 << ")."
988  << (arg2 == arg3 ?
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 "
992  "correct size." :
993  ""));
994 
999  int,
1000  int,
1001  << "Number " << arg1 << " must be larger than or equal "
1002  << arg2 << ".");
1003 
1007  template <typename T>
1009  T,
1010  T,
1011  << "Number " << arg1 << " must be larger than or equal "
1012  << arg2 << ".");
1013 
1019  int,
1020  int,
1021  << "Division " << arg1 << " by " << arg2
1022  << " has remainder different from zero.");
1023 
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.");
1037 
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 "
1046  "case.");
1047 
1061  DeclException1(ExcMessage, std::string, << arg1);
1062 
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 "
1072  "vectors."
1073  "\n\n"
1074  "See the glossary entry on 'Ghosted vectors' for more "
1075  "information.");
1076 
1085  "You are trying an operation of the form 'vector = C', "
1086  "'matrix = C', or 'tensor = C' with a nonzero scalar value "
1087  "'C'. However, such assignments are only allowed if the "
1088  "C is zero, since the semantics for assigning any other "
1089  "value are not clear. For example: one could interpret "
1090  "assigning a matrix a value of 1 to mean the matrix has a "
1091  "norm of 1, the matrix is the identity matrix, or the "
1092  "matrix contains only 1s. Similar problems exist with "
1093  "vectors and tensors. Hence, to avoid this ambiguity, such "
1094  "assignments are not permitted.");
1095 
1101  "You are attempting to use functionality that is only available "
1102  "if deal.II was configured to use LAPACK, but cmake did not "
1103  "find a valid LAPACK library.");
1104 
1109  ExcNeedsMPI,
1110  "You are attempting to use functionality that is only available "
1111  "if deal.II was configured to use MPI.");
1112 
1118  "You are attempting to use functionality that is only available "
1119  "if deal.II was configured to use the function parser which "
1120  "relies on the muparser library, but cmake did not "
1121  "find a valid muparser library on your system and also did "
1122  "not choose the one that comes bundled with deal.II.");
1123 
1129  "You are attempting to use functionality that is only available "
1130  "if deal.II was configured to use Assimp, but cmake did not "
1131  "find a valid Assimp library.");
1132 
1133 #ifdef DEAL_II_WITH_CUDA
1134 
1140  DeclException1(ExcCudaError, const char *, << arg1);
1145  std::string,
1146  << "There was an error in a cuSPARSE function: " << arg1);
1147 #endif
1148 
1149 
1155  "You are attempting to use functionality that is only available if deal.II "
1156  "was configured to use Trilinos' SEACAS library (which provides ExodusII), "
1157  "but cmake did not find a valid SEACAS library.");
1158 
1159 #ifdef DEAL_II_WITH_MPI
1160 
1181  class ExcMPI : public ::ExceptionBase
1182  {
1183  public:
1184  ExcMPI(const int error_code);
1185 
1186  virtual void
1187  print_info(std::ostream &out) const override;
1188 
1189  const int error_code;
1190  };
1191 #endif // DEAL_II_WITH_MPI
1192 
1193 
1194 
1195 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
1196 
1204  class ExcExodusII : public ExceptionBase
1205  {
1206  public:
1212  ExcExodusII(const int error_code);
1213 
1217  virtual void
1218  print_info(std::ostream &out) const override;
1219 
1223  const int error_code;
1224  };
1225 #endif // DEAL_II_TRILINOS_WITH_SEACAS
1226 } /*namespace StandardExceptions*/
1227 
1228 
1229 
1237 {
1238  namespace internals
1239  {
1247  extern bool allow_abort_on_exception;
1248  } // namespace internals
1249 
1268  void
1269  set_additional_assert_output(const char *const p);
1270 
1281  void
1283 
1297  void
1299 
1307  namespace internals
1308  {
1313  [[noreturn]] void
1314  abort(const ExceptionBase &exc) noexcept;
1315 
1320  {
1331  };
1332 
1350  template <class ExceptionType>
1351  [[noreturn]] void
1353  const char * file,
1354  int line,
1355  const char * function,
1356  const char * cond,
1357  const char * exc_name,
1358  ExceptionType e)
1359  {
1360  // Fill the fields of the exception object
1361  e.set_fields(file, line, function, cond, exc_name);
1362 
1363  switch (handling)
1364  {
1366  {
1369  internals::abort(e);
1370  else
1371  {
1372  // We are not allowed to abort, so just throw the error:
1373  throw e;
1374  }
1375  }
1376  case throw_on_exception:
1377  throw e;
1378  // this function should never return (and AssertNothrow can);
1379  // something must have gone wrong in the error handling code for us
1380  // to get this far, so throw an exception.
1381  default:
1383  }
1384  }
1385 
1389  void
1390  do_issue_error_nothrow(const ExceptionBase &e) noexcept;
1391 
1400  template <class ExceptionType>
1401  void
1403  int line,
1404  const char * function,
1405  const char * cond,
1406  const char * exc_name,
1407  ExceptionType e) noexcept
1408  {
1409  static_assert(std::is_base_of<ExceptionBase, ExceptionType>::value,
1410  "The provided exception must inherit from ExceptionBase.");
1411  // Fill the fields of the exception object
1412  e.set_fields(file, line, function, cond, exc_name);
1413  // avoid moving a bunch of code into the header by dispatching to
1414  // another function:
1416  }
1417 #ifdef DEAL_II_WITH_CUDA
1418 
1423  std::string
1424  get_cusparse_error_string(const cusparseStatus_t error_code);
1425 
1431  std::string
1432  get_cusolver_error_string(const cusolverStatus_t error_code);
1433 #endif
1434  } /*namespace internals*/
1435 
1436 } /*namespace deal_II_exceptions*/
1437 
1438 
1439 
1465 #ifdef DEBUG
1466 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1467 # define Assert(cond, exc) \
1468  { \
1469  if (__builtin_expect(!(cond), false)) \
1470  ::deal_II_exceptions::internals::issue_error_noreturn( \
1471  ::deal_II_exceptions::internals:: \
1472  abort_or_throw_on_exception, \
1473  __FILE__, \
1474  __LINE__, \
1475  __PRETTY_FUNCTION__, \
1476  #cond, \
1477  #exc, \
1478  exc); \
1479  }
1480 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1481 # define Assert(cond, exc) \
1482  { \
1483  if (!(cond)) \
1484  ::deal_II_exceptions::internals::issue_error_noreturn( \
1485  ::deal_II_exceptions::internals:: \
1486  abort_or_throw_on_exception, \
1487  __FILE__, \
1488  __LINE__, \
1489  __PRETTY_FUNCTION__, \
1490  #cond, \
1491  #exc, \
1492  exc); \
1493  }
1494 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1495 #else
1496 # define Assert(cond, exc) \
1497  {}
1498 #endif
1499 
1500 
1501 
1528 #ifdef DEBUG
1529 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1530 # define AssertNothrow(cond, exc) \
1531  { \
1532  if (__builtin_expect(!(cond), false)) \
1533  ::deal_II_exceptions::internals::issue_error_nothrow( \
1534  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1535  }
1536 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1537 # define AssertNothrow(cond, exc) \
1538  { \
1539  if (!(cond)) \
1540  ::deal_II_exceptions::internals::issue_error_nothrow( \
1541  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1542  }
1543 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1544 #else
1545 # define AssertNothrow(cond, exc) \
1546  {}
1547 #endif
1548 
1576 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1577 # define AssertThrow(cond, exc) \
1578  { \
1579  if (__builtin_expect(!(cond), false)) \
1580  ::deal_II_exceptions::internals::issue_error_noreturn( \
1581  ::deal_II_exceptions::internals::throw_on_exception, \
1582  __FILE__, \
1583  __LINE__, \
1584  __PRETTY_FUNCTION__, \
1585  #cond, \
1586  #exc, \
1587  exc); \
1588  }
1589 #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1590 # define AssertThrow(cond, exc) \
1591  { \
1592  if (!(cond)) \
1593  ::deal_II_exceptions::internals::issue_error_noreturn( \
1594  ::deal_II_exceptions::internals::throw_on_exception, \
1595  __FILE__, \
1596  __LINE__, \
1597  __PRETTY_FUNCTION__, \
1598  #cond, \
1599  #exc, \
1600  exc); \
1601  }
1602 #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1603 
1604 
1605 namespace deal_II_exceptions
1606 {
1607  namespace internals
1608  {
1614  template <typename T, typename U>
1615  inline constexpr bool
1616  compare_for_equality(const T &t, const U &u)
1617  {
1618  using common_type = typename std::common_type<T, U>::type;
1619  return static_cast<common_type>(t) == static_cast<common_type>(u);
1620  }
1621 
1622 
1628  template <typename T, typename U>
1629  inline constexpr bool
1630  compare_less_than(const T &t, const U &u)
1631  {
1632  using common_type = typename std::common_type<T, U>::type;
1633  return (static_cast<common_type>(t) < static_cast<common_type>(u));
1634  }
1635  } // namespace internals
1636 } // namespace deal_II_exceptions
1637 
1638 
1659 #define AssertDimension(dim1, dim2) \
1660  Assert(::deal_II_exceptions::internals::compare_for_equality(dim1, \
1661  dim2), \
1662  ::ExcDimensionMismatch((dim1), (dim2)))
1663 
1664 
1682 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \
1683  AssertDimension(VEC.size(), DIM1); \
1684  for (const auto &subvector : VEC) \
1685  { \
1686  (void)subvector; \
1687  AssertDimension(subvector.size(), DIM2); \
1688  }
1689 
1690 namespace internal
1691 {
1692  // Workaround to allow for commas in template parameter lists
1693  // in preprocessor macros as found in
1694  // https://stackoverflow.com/questions/13842468/comma-in-c-c-macro
1695  template <typename T>
1697 
1698  template <typename T, typename U>
1699  struct argument_type<T(U)>
1700  {
1701  using type = U;
1702  };
1703 } // namespace internal
1704 
1724 #define AssertIndexRange(index, range) \
1725  Assert( \
1726  ::deal_II_exceptions::internals::compare_less_than(index, range), \
1727  ExcIndexRangeType<typename ::internal::argument_type<void( \
1728  typename std::common_type<decltype(index), decltype(range)>::type)>:: \
1729  type>((index), 0, (range)))
1730 
1750 #define AssertIsFinite(number) \
1751  Assert(::numbers::is_finite(number), \
1752  ::ExcNumberNotFinite(std::complex<double>(number)))
1753 
1759 #define AssertIsNotUsed(obj) Assert((obj)->used() == false, ExcInternalError())
1760 
1761 #ifdef DEAL_II_WITH_MPI
1762 
1782 # define AssertThrowMPI(error_code) \
1783  AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code))
1784 #else
1785 # define AssertThrowMPI(error_code) \
1786  {}
1787 #endif // DEAL_II_WITH_MPI
1788 
1789 #ifdef DEAL_II_WITH_CUDA
1790 
1807 # ifdef DEBUG
1808 # define AssertCuda(error_code) \
1809  Assert(error_code == cudaSuccess, \
1810  ::ExcCudaError(cudaGetErrorString(error_code)))
1811 # else
1812 # define AssertCuda(error_code) \
1813  { \
1814  (void)(error_code); \
1815  }
1816 # endif
1817 
1834 # ifdef DEBUG
1835 # define AssertNothrowCuda(error_code) \
1836  AssertNothrow(error_code == cudaSuccess, \
1837  ::ExcCudaError(cudaGetErrorString(error_code)))
1838 # else
1839 # define AssertNothrowCuda(error_code) \
1840  { \
1841  (void)(error_code); \
1842  }
1843 # endif
1844 
1862 # ifdef DEBUG
1863 # define AssertCudaKernel() \
1864  { \
1865  cudaError_t local_error_code = cudaPeekAtLastError(); \
1866  AssertCuda(local_error_code); \
1867  local_error_code = cudaDeviceSynchronize(); \
1868  AssertCuda(local_error_code) \
1869  }
1870 # else
1871 # define AssertCudaKernel() \
1872  {}
1873 # endif
1874 
1892 # ifdef DEBUG
1893 # define AssertCusparse(error_code) \
1894  Assert( \
1895  error_code == CUSPARSE_STATUS_SUCCESS, \
1896  ExcCusparseError( \
1897  deal_II_exceptions::internals::get_cusparse_error_string( \
1898  error_code)))
1899 # else
1900 # define AssertCusparse(error_code) \
1901  { \
1902  (void)(error_code); \
1903  }
1904 # endif
1905 
1922 # ifdef DEBUG
1923 # define AssertNothrowCusparse(error_code) \
1924  AssertNothrow( \
1925  error_code == CUSPARSE_STATUS_SUCCESS, \
1926  ExcCusparseError( \
1927  deal_II_exceptions::internals::get_cusparse_error_string( \
1928  error_code)))
1929 # else
1930 # define AssertNothrowCusparse(error_code) \
1931  { \
1932  (void)(error_code); \
1933  }
1934 # endif
1935 
1953 # ifdef DEBUG
1954 # define AssertCusolver(error_code) \
1955  Assert( \
1956  error_code == CUSOLVER_STATUS_SUCCESS, \
1957  ExcCusparseError( \
1958  deal_II_exceptions::internals::get_cusolver_error_string( \
1959  error_code)))
1960 # else
1961 # define AssertCusolver(error_code) \
1962  { \
1963  (void)(error_code); \
1964  }
1965 # endif
1966 
1967 #endif
1968 
1969 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
1970 
1987 # define AssertThrowExodusII(error_code) \
1988  AssertThrow(error_code == 0, ExcExodusII(error_code));
1989 #endif // DEAL_II_TRILINOS_WITH_SEACAS
1990 
1991 using namespace StandardExceptions;
1992 
1994 
1995 #endif
static ::ExceptionBase & ExcCudaError(const char *arg1)
static ::ExceptionBase & ExcPureFunctionCalled()
static ::ExceptionBase & ExcNeedsFunctionparser()
static ::ExceptionBase & ExcNeedsExodusII()
static ::ExceptionBase & ExcNeedsMPI()
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:538
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
void suppress_stacktrace_in_exceptions()
Definition: exceptions.cc:69
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
Definition: exceptions.cc:119
std::string get_cusolver_error_string(const cusolverStatus_t error_code)
Definition: exceptions.cc:558
static const char U
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]
Definition: exceptions.h:160
virtual void print_info(std::ostream &out) const
Definition: exceptions.cc:214
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
Definition: exceptions.cc:151
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:515
static const char T
static ::ExceptionBase & ExcMemoryLeak(int arg1)
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
Definition: exceptions.cc:128
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
Definition: exceptions.cc:495
static ::ExceptionBase & ExcOutOfMemory(std::size_t arg1)
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
Definition: exceptions.cc:512
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:493
#define DeclException0(Exception0)
Definition: exceptions.h:470
void abort(const ExceptionBase &exc) noexcept
Definition: exceptions.cc:449
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
static ::ExceptionBase & ExcNeedsAssimp()
static ::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
std::string what_str
Definition: exceptions.h:174
unsigned int line
Definition: exceptions.h:127
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
void print_stack_trace(std::ostream &out) const
Definition: exceptions.cc:222
static ::ExceptionBase & ExcGhostsPresent()
static ::ExceptionBase & ExcIteratorPastEnd()
const char * exc
Definition: exceptions.h:142
const char * cond
Definition: exceptions.h:137
constexpr bool compare_less_than(const T &t, const U &u)
Definition: exceptions.h:1630
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)
Definition: exceptions.h:1352
void issue_error_nothrow(const char *file, int line, const char *function, const char *cond, const char *exc_name, ExceptionType e) noexcept
Definition: exceptions.h:1402
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
const char * file
Definition: exceptions.h:122
static ::ExceptionBase & ExcCusparseError(std::string arg1)
static ::ExceptionBase & ExcEmptyObject()
void print_exc_data(std::ostream &out) const
Definition: exceptions.cc:182
static ::ExceptionBase & ExcNotMultiple(int arg1, int arg2)
constexpr bool compare_for_equality(const T &t, const U &u)
Definition: exceptions.h:1616
static ::ExceptionBase & ExcNotImplemented()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:561
void generate_message() const
Definition: exceptions.cc:311
char ** stacktrace
Definition: exceptions.h:148
void disable_abort_on_exception()
Definition: exceptions.cc:75
const char * get_exc_name() const
Definition: exceptions.cc:174
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcFileNotOpen(std::string arg1)
int n_stacktrace_frames
Definition: exceptions.h:154
static ::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
static ::ExceptionBase & ExcInternalError()