Reference documentation for deal.II version GIT eef19498cf 2022-10-05 14:45:02+00:00
\(\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 - 2022 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 = default;
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 
149 
150 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
154  void *raw_stacktrace[25];
155 #endif
156 
157 private:
161  void
162  generate_message() const;
163 
168  mutable std::string what_str;
169 };
170 
171 #ifndef DOXYGEN
172 
189 # define DeclException0(Exception0) \
190  class Exception0 : public ::ExceptionBase \
191  {}
192 
193 
213 # define DeclExceptionMsg(Exception, defaulttext) \
214  class Exception : public ::ExceptionBase \
215  { \
216  public: \
217  Exception(const std::string &msg = defaulttext) \
218  : arg(msg) \
219  {} \
220  virtual ~Exception() noexcept \
221  {} \
222  virtual void \
223  print_info(std::ostream &out) const override \
224  { \
225  out << " " << arg << std::endl; \
226  } \
227  \
228  private: \
229  const std::string arg; \
230  }
231 
249 # define DeclException1(Exception1, type1, outsequence) \
250  class Exception1 : public ::ExceptionBase \
251  { \
252  public: \
253  Exception1(type1 const &a1) \
254  : arg1(a1) \
255  {} \
256  virtual ~Exception1() noexcept \
257  {} \
258  virtual void \
259  print_info(std::ostream &out) const override \
260  { \
261  out << " " outsequence << std::endl; \
262  } \
263  \
264  private: \
265  type1 const arg1; \
266  }
267 
268 
286 # define DeclException2(Exception2, type1, type2, outsequence) \
287  class Exception2 : public ::ExceptionBase \
288  { \
289  public: \
290  Exception2(type1 const &a1, type2 const &a2) \
291  : arg1(a1) \
292  , arg2(a2) \
293  {} \
294  virtual ~Exception2() noexcept \
295  {} \
296  virtual void \
297  print_info(std::ostream &out) const override \
298  { \
299  out << " " outsequence << std::endl; \
300  } \
301  \
302  private: \
303  type1 const arg1; \
304  type2 const arg2; \
305  }
306 
307 
325 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
326  class Exception3 : public ::ExceptionBase \
327  { \
328  public: \
329  Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \
330  : arg1(a1) \
331  , arg2(a2) \
332  , arg3(a3) \
333  {} \
334  virtual ~Exception3() noexcept \
335  {} \
336  virtual void \
337  print_info(std::ostream &out) const override \
338  { \
339  out << " " outsequence << std::endl; \
340  } \
341  \
342  private: \
343  type1 const arg1; \
344  type2 const arg2; \
345  type3 const arg3; \
346  }
347 
348 
366 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
367  class Exception4 : public ::ExceptionBase \
368  { \
369  public: \
370  Exception4(type1 const &a1, \
371  type2 const &a2, \
372  type3 const &a3, \
373  type4 const &a4) \
374  : arg1(a1) \
375  , arg2(a2) \
376  , arg3(a3) \
377  , arg4(a4) \
378  {} \
379  virtual ~Exception4() noexcept \
380  {} \
381  virtual void \
382  print_info(std::ostream &out) const override \
383  { \
384  out << " " outsequence << std::endl; \
385  } \
386  \
387  private: \
388  type1 const arg1; \
389  type2 const arg2; \
390  type3 const arg3; \
391  type4 const arg4; \
392  }
393 
394 
412 # define DeclException5( \
413  Exception5, type1, type2, type3, type4, type5, outsequence) \
414  class Exception5 : public ::ExceptionBase \
415  { \
416  public: \
417  Exception5(type1 const &a1, \
418  type2 const &a2, \
419  type3 const &a3, \
420  type4 const &a4, \
421  type5 const &a5) \
422  : arg1(a1) \
423  , arg2(a2) \
424  , arg3(a3) \
425  , arg4(a4) \
426  , arg5(a5) \
427  {} \
428  virtual ~Exception5() noexcept \
429  {} \
430  virtual void \
431  print_info(std::ostream &out) const override \
432  { \
433  out << " " outsequence << std::endl; \
434  } \
435  \
436  private: \
437  type1 const arg1; \
438  type2 const arg2; \
439  type3 const arg3; \
440  type4 const arg4; \
441  type5 const arg5; \
442  }
443 
444 #else /*ifndef DOXYGEN*/
445 
446 // Dummy definitions for doxygen:
447 
464 # define DeclException0(Exception0) \
465  \
466  static ::ExceptionBase &Exception0()
467 
487 # define DeclExceptionMsg(Exception, defaulttext) \
488  \
489  \
490  static ::ExceptionBase &Exception()
491 
509 # define DeclException1(Exception1, type1, outsequence) \
510  \
511  \
512  static ::ExceptionBase &Exception1(type1 arg1)
513 
514 
532 # define DeclException2(Exception2, type1, type2, outsequence) \
533  \
534  \
535  static ::ExceptionBase &Exception2(type1 arg1, type2 arg2)
536 
537 
555 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
556  \
557  \
558  static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3)
559 
560 
578 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
579  \
580  \
581  static ::ExceptionBase &Exception4(type1 arg1, \
582  type2 arg2, \
583  type3 arg3, \
584  type4 arg4)
585 
586 
604 # define DeclException5( \
605  Exception5, type1, type2, type3, type4, type5, outsequence) \
606  \
607  \
608  static ::ExceptionBase &Exception5( \
609  type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)
610 
611 #endif /*ifndef DOXYGEN*/
612 
613 
626 {
636  "A piece of code is attempting a division by zero. This is "
637  "likely going to lead to results that make no sense.");
638 
651  std::complex<double>,
652  << "In a significant number of places, deal.II checks that some intermediate "
653  << "value is a finite number (as opposed to plus or minus infinity, or "
654  << "NaN/Not a Number). In the current function, we encountered a number "
655  << "that is not finite (its value is " << arg1 << " and therefore "
656  << "violates the current assertion).\n\n"
657  << "This may be due to the fact that some operation in this function "
658  << "created such a value, or because one of the arguments you passed "
659  << "to the function already had this value from some previous "
660  << "operation. In the latter case, this function only triggered the "
661  << "error but may not actually be responsible for the computation of "
662  << "the number that is not finite.\n\n"
663  << "There are two common cases where this situation happens. First, your "
664  << "code (or something in deal.II) divides by zero in a place where this "
665  << "should not happen. Or, you are trying to solve a linear system "
666  << "with an unsuitable solver (such as an indefinite or non-symmetric "
667  << "linear system using a Conjugate Gradient solver); such attempts "
668  << "oftentimes yield an operation somewhere that tries to divide "
669  << "by zero or take the square root of a negative value.\n\n"
670  << "In any case, when trying to find the source of the error, "
671  << "recall that the location where you are getting this error is "
672  << "simply the first place in the program where there is a check "
673  << "that a number (e.g., an element of a solution vector) is in fact "
674  << "finite, but that the actual error that computed the number "
675  << "may have happened far earlier. To find this location, you "
676  << "may want to add checks for finiteness in places of your "
677  << "program visited before the place where this error is produced. "
678  << "One way to check for finiteness is to use the 'AssertIsFinite' "
679  << "macro.");
680 
685  std::size_t,
686  "Your program tried to allocate some memory but this "
687  "allocation failed. Typically, this either means that "
688  "you simply do not have enough memory in your system, "
689  "or that you are (erroneously) trying to allocate "
690  "a chunk of memory that is simply beyond all reasonable "
691  "size, for example because the size of the object has "
692  "been computed incorrectly."
693  "\n\n"
694  "In the current case, the request was for "
695  << arg1 << " bytes.");
696 
702  int,
703  << "Destroying memory handler while " << arg1
704  << " objects are still allocated.");
705 
710  "An input/output error has occurred. There are a number of "
711  "reasons why this may be happening, both for reading and "
712  "writing operations."
713  "\n\n"
714  "If this happens during an operation that tries to read "
715  "data: First, you may be "
716  "trying to read from a file that doesn't exist or that is "
717  "not readable given its file permissions. Second, deal.II "
718  "uses this error at times if it tries to "
719  "read information from a file but where the information "
720  "in the file does not correspond to the expected format. "
721  "An example would be a truncated file, or a mesh file "
722  "that contains not only sections that describe the "
723  "vertices and cells, but also sections for additional "
724  "data that deal.II does not understand."
725  "\n\n"
726  "If this happens during an operation that tries to write "
727  "data: you may be trying to write to a file to which file "
728  "or directory permissions do not allow you to write. A "
729  "typical example is where you specify an output file in "
730  "a directory that does not exist.");
731 
739  std::string,
740  << "Could not open file " << arg1
741  << "."
742  "\n\n"
743  "If this happens during an operation that tries to read "
744  "data: you may be "
745  "trying to read from a file that doesn't exist or that is "
746  "not readable given its file permissions."
747  "\n\n"
748  "If this happens during an operation that tries to write "
749  "data: you may be trying to write to a file to which file "
750  "or directory permissions do not allow you to write. A "
751  "typical example is where you specify an output file in "
752  "a directory that does not exist.");
753 
763  "You are trying to use functionality in deal.II that is "
764  "currently not implemented. In many cases, this indicates "
765  "that there simply didn't appear much of a need for it, or "
766  "that the author of the original code did not have the "
767  "time to implement a particular case. If you hit this "
768  "exception, it is therefore worth the time to look into "
769  "the code to find out whether you may be able to "
770  "implement the missing functionality. If you do, please "
771  "consider providing a patch to the deal.II development "
772  "sources (see the deal.II website on how to contribute).");
773 
795  "This exception -- which is used in many places in the "
796  "library -- usually indicates that some condition which "
797  "the author of the code thought must be satisfied at a "
798  "certain point in an algorithm, is not fulfilled. An "
799  "example would be that the first part of an algorithm "
800  "sorts elements of an array in ascending order, and "
801  "a second part of the algorithm later encounters an "
802  "element that is not larger than the previous one."
803  "\n\n"
804  "There is usually not very much you can do if you "
805  "encounter such an exception since it indicates an error "
806  "in deal.II, not in your own program. Try to come up with "
807  "the smallest possible program that still demonstrates "
808  "the error and contact the deal.II mailing lists with it "
809  "to obtain help.");
810 
819  "You (or a place in the library) are trying to call a "
820  "function that is declared as a virtual function in a "
821  "base class but that has not been overridden in your "
822  "derived class."
823  "\n\n"
824  "This exception happens in cases where the base class "
825  "cannot provide a useful default implementation for "
826  "the virtual function, but where we also do not want "
827  "to mark the function as abstract (i.e., with '=0' at the end) "
828  "because the function is not essential to the class in many "
829  "contexts. In cases like this, the base class provides "
830  "a dummy implementation that makes the compiler happy, but "
831  "that then throws the current exception."
832  "\n\n"
833  "A concrete example would be the 'Function' class. It declares "
834  "the existence of 'value()' and 'gradient()' member functions, "
835  "and both are marked as 'virtual'. Derived classes have to "
836  "override these functions for the values and gradients of a "
837  "particular function. On the other hand, not every function "
838  "has a gradient, and even for those that do, not every program "
839  "actually needs to evaluate it. Consequently, there is no "
840  "*requirement* that a derived class actually override the "
841  "'gradient()' function (as there would be had it been marked "
842  "as abstract). But, since the base class cannot know how to "
843  "compute the gradient, if a derived class does not override "
844  "the 'gradient()' function and it is called anyway, then the "
845  "default implementation in the base class will simply throw "
846  "an exception."
847  "\n\n"
848  "The exception you see is what happens in cases such as the "
849  "one just illustrated. To fix the problem, you need to "
850  "investigate whether the function being called should indeed have "
851  "been called; if the answer is 'yes', then you need to "
852  "implement the missing override in your class.");
853 
858 
863 
871  int,
872  << "You are trying to execute functionality that is "
873  << "impossible in " << arg1
874  << "d or simply does not make any sense.");
875 
884  int,
885  int,
886  << "You are trying to execute functionality that is "
887  << "impossible in dimensions <" << arg1 << ',' << arg2
888  << "> or simply does not make any sense.");
889 
890 
895  "In a check in the code, deal.II encountered a zero in "
896  "a place where this does not make sense. See the condition "
897  "that was being checked and that is printed further up "
898  "in the error message to get more information on what "
899  "the erroneous zero corresponds to.");
900 
906  "The object you are trying to access is empty but it makes "
907  "no sense to attempt the operation you are trying on an "
908  "empty object.");
909 
918  std::size_t,
919  std::size_t,
920  << "Dimension " << arg1 << " not equal to " << arg2 << '.');
921 
927  std::size_t,
928  std::size_t,
929  std::size_t,
930  << "Dimension " << arg1 << " neither equal to " << arg2
931  << " nor to " << arg3 << '.');
932 
947  std::size_t,
948  std::size_t,
949  std::size_t,
950  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
951  << arg3 << ")."
952  << (arg2 == arg3 ?
953  " In the current case, this half-open range is in fact empty, "
954  "suggesting that you are accessing an element of an empty "
955  "collection such as a vector that has not been set to the "
956  "correct size." :
957  ""));
958 
974  template <typename T>
977  T,
978  T,
979  T,
980  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
981  << arg3 << ")."
982  << (arg2 == arg3 ?
983  " In the current case, this half-open range is in fact empty, "
984  "suggesting that you are accessing an element of an empty "
985  "collection such as a vector that has not been set to the "
986  "correct size." :
987  ""));
988 
993  int,
994  int,
995  << "Number " << arg1 << " must be larger than or equal "
996  << arg2 << '.');
997 
1001  template <typename T>
1003  T,
1004  T,
1005  << "Number " << arg1 << " must be larger than or equal "
1006  << arg2 << '.');
1007 
1013  int,
1014  int,
1015  << "Division " << arg1 << " by " << arg2
1016  << " has remainder different from zero.");
1017 
1027  "You are trying to use an iterator, but the iterator is "
1028  "in an invalid state. This may indicate that the iterator "
1029  "object has not been initialized, or that it has been "
1030  "moved beyond the end of the range of valid elements.");
1031 
1037  "You are trying to use an iterator, but the iterator is "
1038  "pointing past the end of the range of valid elements. "
1039  "It is not valid to dereference the iterator in this "
1040  "case.");
1041 
1055  DeclException1(ExcMessage, std::string, << arg1);
1056 
1061  "You are trying an operation on a vector that is only "
1062  "allowed if the vector has no ghost elements, but the "
1063  "vector you are operating on does have ghost elements. "
1064  "Specifically, vectors with ghost elements are read-only "
1065  "and cannot appear in operations that write into these "
1066  "vectors."
1067  "\n\n"
1068  "See the glossary entry on 'Ghosted vectors' for more "
1069  "information.");
1070 
1076  int,
1077  << "Something went wrong when making cell " << arg1
1078  << ". Read the docs and the source code "
1079  << "for more information.");
1080 
1089  "You are trying an operation of the form 'vector = C', "
1090  "'matrix = C', or 'tensor = C' with a nonzero scalar value "
1091  "'C'. However, such assignments are only allowed if the "
1092  "C is zero, since the semantics for assigning any other "
1093  "value are not clear. For example: one could interpret "
1094  "assigning a matrix a value of 1 to mean the matrix has a "
1095  "norm of 1, the matrix is the identity matrix, or the "
1096  "matrix contains only 1s. Similar problems exist with "
1097  "vectors and tensors. Hence, to avoid this ambiguity, such "
1098  "assignments are not permitted.");
1099 
1105  "You are attempting to use functionality that is only available "
1106  "if deal.II was configured to use LAPACK, but cmake did not "
1107  "find a valid LAPACK library.");
1108 
1113  ExcNeedsHDF5,
1114  "You are attempting to use functionality that requires that deal.II is configured "
1115  "with HDF5 support. However, when you called 'cmake', HDF5 support "
1116  "was not detected.");
1117 
1122  ExcNeedsMPI,
1123  "You are attempting to use functionality that is only available "
1124  "if deal.II was configured to use MPI.");
1125 
1131  "You are attempting to use functionality that is only available "
1132  "if deal.II was configured to use the function parser which "
1133  "relies on the muparser library, but cmake did not "
1134  "find a valid muparser library on your system and also did "
1135  "not choose the one that comes bundled with deal.II.");
1136 
1142  "You are attempting to use functionality that is only available "
1143  "if deal.II was configured to use Assimp, but cmake did not "
1144  "find a valid Assimp library.");
1145 
1146 #ifdef DEAL_II_WITH_CUDA
1153  DeclException1(ExcCudaError, const char *, << arg1);
1158  std::string,
1159  << "There was an error in a cuSPARSE function: " << arg1);
1160 #endif
1168  "You are attempting to use functionality that is only available if deal.II "
1169  "was configured to use Trilinos' SEACAS library (which provides ExodusII), "
1170  "but cmake did not find a valid SEACAS library.");
1171 
1176  ExcNeedsCGAL,
1177  "You are attempting to use functionality that is only available "
1178  "if deal.II was configured to use CGAL, but cmake did not "
1179  "find a valid CGAL library.");
1180 
1181 #ifdef DEAL_II_WITH_MPI
1203  class ExcMPI : public ::ExceptionBase
1204  {
1205  public:
1206  ExcMPI(const int error_code);
1207 
1208  virtual void
1209  print_info(std::ostream &out) const override;
1210 
1211  const int error_code;
1212  };
1213 #endif // DEAL_II_WITH_MPI
1214 
1215 
1216 
1217 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
1226  class ExcExodusII : public ExceptionBase
1227  {
1228  public:
1234  ExcExodusII(const int error_code);
1235 
1239  virtual void
1240  print_info(std::ostream &out) const override;
1241 
1245  const int error_code;
1246  };
1247 #endif // DEAL_II_TRILINOS_WITH_SEACAS
1248 } /*namespace StandardExceptions*/
1249 
1250 
1251 
1259 {
1260  namespace internals
1261  {
1269  extern bool allow_abort_on_exception;
1270  } // namespace internals
1271 
1290  void
1291  set_additional_assert_output(const char *const p);
1292 
1303  void
1305 
1320  void
1322 
1331  void
1333 
1341  namespace internals
1342  {
1347  [[noreturn]] void
1348  abort(const ExceptionBase &exc) noexcept;
1349 
1354  {
1365  };
1366 
1384  template <class ExceptionType>
1385  [[noreturn]] void
1387  const char * file,
1388  int line,
1389  const char * function,
1390  const char * cond,
1391  const char * exc_name,
1392  ExceptionType e)
1393  {
1394  // Fill the fields of the exception object
1395  e.set_fields(file, line, function, cond, exc_name);
1396 
1397  switch (handling)
1398  {
1400  {
1404  else
1405  {
1406  // We are not allowed to abort, so just throw the error:
1407  throw e;
1408  }
1409  }
1411  throw e;
1412  // this function should never return (and AssertNothrow can);
1413  // something must have gone wrong in the error handling code for us
1414  // to get this far, so throw an exception.
1415  default:
1417  }
1418  }
1419 
1423  void
1424  do_issue_error_nothrow(const ExceptionBase &e) noexcept;
1425 
1434  template <class ExceptionType>
1435  void
1436  issue_error_nothrow(const char * file,
1437  int line,
1438  const char * function,
1439  const char * cond,
1440  const char * exc_name,
1441  ExceptionType e) noexcept
1442  {
1443  static_assert(std::is_base_of<ExceptionBase, ExceptionType>::value,
1444  "The provided exception must inherit from ExceptionBase.");
1445  // Fill the fields of the exception object
1446  e.set_fields(file, line, function, cond, exc_name);
1447  // avoid moving a bunch of code into the header by dispatching to
1448  // another function:
1450  }
1451 #ifdef DEAL_II_WITH_CUDA
1457  std::string
1458  get_cusparse_error_string(const cusparseStatus_t error_code);
1459 
1465  std::string
1466  get_cusolver_error_string(const cusolverStatus_t error_code);
1467 #endif
1468  } /*namespace internals*/
1469 
1470 } /*namespace deal_II_exceptions*/
1471 
1472 
1473 
1499 #ifdef DEBUG
1500 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1501 # define Assert(cond, exc) \
1502  { \
1503  if (__builtin_expect(!(cond), false)) \
1504  ::deal_II_exceptions::internals::issue_error_noreturn( \
1505  ::deal_II_exceptions::internals::ExceptionHandling:: \
1506  abort_or_throw_on_exception, \
1507  __FILE__, \
1508  __LINE__, \
1509  __PRETTY_FUNCTION__, \
1510  #cond, \
1511  #exc, \
1512  exc); \
1513  }
1514 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1515 # define Assert(cond, exc) \
1516  { \
1517  if (!(cond)) \
1518  ::deal_II_exceptions::internals::issue_error_noreturn( \
1519  ::deal_II_exceptions::internals::ExceptionHandling:: \
1520  abort_or_throw_on_exception, \
1521  __FILE__, \
1522  __LINE__, \
1523  __PRETTY_FUNCTION__, \
1524  #cond, \
1525  #exc, \
1526  exc); \
1527  }
1528 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1529 #else
1530 # define Assert(cond, exc) \
1531  {}
1532 #endif
1533 
1534 
1535 
1562 #ifdef DEBUG
1563 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1564 # define AssertNothrow(cond, exc) \
1565  { \
1566  if (__builtin_expect(!(cond), false)) \
1567  ::deal_II_exceptions::internals::issue_error_nothrow( \
1568  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1569  }
1570 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1571 # define AssertNothrow(cond, exc) \
1572  { \
1573  if (!(cond)) \
1574  ::deal_II_exceptions::internals::issue_error_nothrow( \
1575  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1576  }
1577 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1578 #else
1579 # define AssertNothrow(cond, exc) \
1580  {}
1581 #endif
1582 
1610 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1611 # define AssertThrow(cond, exc) \
1612  { \
1613  if (__builtin_expect(!(cond), false)) \
1614  ::deal_II_exceptions::internals::issue_error_noreturn( \
1615  ::deal_II_exceptions::internals::ExceptionHandling:: \
1616  throw_on_exception, \
1617  __FILE__, \
1618  __LINE__, \
1619  __PRETTY_FUNCTION__, \
1620  #cond, \
1621  #exc, \
1622  exc); \
1623  }
1624 #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1625 # define AssertThrow(cond, exc) \
1626  { \
1627  if (!(cond)) \
1628  ::deal_II_exceptions::internals::issue_error_noreturn( \
1629  ::deal_II_exceptions::internals::ExceptionHandling:: \
1630  throw_on_exception, \
1631  __FILE__, \
1632  __LINE__, \
1633  __PRETTY_FUNCTION__, \
1634  #cond, \
1635  #exc, \
1636  exc); \
1637  }
1638 #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1639 
1640 
1641 namespace deal_II_exceptions
1642 {
1643  namespace internals
1644  {
1650  template <typename T, typename U>
1651  inline constexpr bool
1652  compare_for_equality(const T &t, const U &u)
1653  {
1654  using common_type = typename std::common_type<T, U>::type;
1655  return static_cast<common_type>(t) == static_cast<common_type>(u);
1656  }
1657 
1658 
1664  template <typename T, typename U>
1665  inline constexpr bool
1666  compare_less_than(const T &t, const U &u)
1667  {
1668  using common_type = typename std::common_type<T, U>::type;
1669  return (static_cast<common_type>(t) < static_cast<common_type>(u));
1670  }
1671  } // namespace internals
1672 } // namespace deal_II_exceptions
1673 
1674 
1695 #define AssertDimension(dim1, dim2) \
1696  Assert(::deal_II_exceptions::internals::compare_for_equality(dim1, \
1697  dim2), \
1698  ::ExcDimensionMismatch((dim1), (dim2)))
1699 
1700 
1718 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \
1719  AssertDimension(VEC.size(), DIM1); \
1720  for (const auto &subvector : VEC) \
1721  { \
1722  (void)subvector; \
1723  AssertDimension(subvector.size(), DIM2); \
1724  }
1725 
1726 namespace internal
1727 {
1728  // Workaround to allow for commas in template parameter lists
1729  // in preprocessor macros as found in
1730  // https://stackoverflow.com/questions/13842468/comma-in-c-c-macro
1731  template <typename T>
1733 
1734  template <typename T, typename U>
1735  struct argument_type<T(U)>
1736  {
1737  using type = U;
1738  };
1739 } // namespace internal
1740 
1760 #define AssertIndexRange(index, range) \
1761  Assert( \
1762  ::deal_II_exceptions::internals::compare_less_than(index, range), \
1763  ExcIndexRangeType<typename ::internal::argument_type<void( \
1764  typename std::common_type<decltype(index), decltype(range)>::type)>:: \
1765  type>((index), 0, (range)))
1766 
1786 #define AssertIsFinite(number) \
1787  Assert(::numbers::is_finite(number), \
1788  ::ExcNumberNotFinite(std::complex<double>(number)))
1789 
1795 #define AssertIsNotUsed(obj) Assert((obj)->used() == false, ExcInternalError())
1796 
1797 #ifdef DEAL_II_WITH_MPI
1818 # define AssertThrowMPI(error_code) \
1819  AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code))
1820 #else
1821 # define AssertThrowMPI(error_code) \
1822  {}
1823 #endif // DEAL_II_WITH_MPI
1824 
1825 #ifdef DEAL_II_WITH_CUDA
1843 # ifdef DEBUG
1844 # define AssertCuda(error_code) \
1845  Assert(error_code == cudaSuccess, \
1846  ::ExcCudaError(cudaGetErrorString(error_code)))
1847 # else
1848 # define AssertCuda(error_code) \
1849  { \
1850  (void)(error_code); \
1851  }
1852 # endif
1853 
1870 # ifdef DEBUG
1871 # define AssertNothrowCuda(error_code) \
1872  AssertNothrow(error_code == cudaSuccess, \
1873  ::ExcCudaError(cudaGetErrorString(error_code)))
1874 # else
1875 # define AssertNothrowCuda(error_code) \
1876  { \
1877  (void)(error_code); \
1878  }
1879 # endif
1880 
1898 # ifdef DEBUG
1899 # define AssertCudaKernel() \
1900  { \
1901  cudaError_t local_error_code = cudaPeekAtLastError(); \
1902  AssertCuda(local_error_code); \
1903  local_error_code = cudaDeviceSynchronize(); \
1904  AssertCuda(local_error_code) \
1905  }
1906 # else
1907 # define AssertCudaKernel() \
1908  {}
1909 # endif
1910 
1928 # ifdef DEBUG
1929 # define AssertCusparse(error_code) \
1930  Assert( \
1931  error_code == CUSPARSE_STATUS_SUCCESS, \
1932  ExcCusparseError( \
1933  deal_II_exceptions::internals::get_cusparse_error_string( \
1934  error_code)))
1935 # else
1936 # define AssertCusparse(error_code) \
1937  { \
1938  (void)(error_code); \
1939  }
1940 # endif
1941 
1958 # ifdef DEBUG
1959 # define AssertNothrowCusparse(error_code) \
1960  AssertNothrow( \
1961  error_code == CUSPARSE_STATUS_SUCCESS, \
1962  ExcCusparseError( \
1963  deal_II_exceptions::internals::get_cusparse_error_string( \
1964  error_code)))
1965 # else
1966 # define AssertNothrowCusparse(error_code) \
1967  { \
1968  (void)(error_code); \
1969  }
1970 # endif
1971 
1989 # ifdef DEBUG
1990 # define AssertCusolver(error_code) \
1991  Assert( \
1992  error_code == CUSOLVER_STATUS_SUCCESS, \
1993  ExcCusparseError( \
1994  deal_II_exceptions::internals::get_cusolver_error_string( \
1995  error_code)))
1996 # else
1997 # define AssertCusolver(error_code) \
1998  { \
1999  (void)(error_code); \
2000  }
2001 # endif
2002 
2003 #endif
2004 
2005 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
2023 # define AssertThrowExodusII(error_code) \
2024  AssertThrow(error_code == 0, ExcExodusII(error_code));
2025 #endif // DEAL_II_TRILINOS_WITH_SEACAS
2026 
2027 using namespace StandardExceptions;
2028 
2030 
2031 #endif
void generate_message() const
Definition: exceptions.cc:322
void print_stack_trace(std::ostream &out) const
Definition: exceptions.cc:221
const char * file
Definition: exceptions.h:122
std::string what_str
Definition: exceptions.h:168
const char * get_exc_name() const
Definition: exceptions.cc:173
virtual ~ExceptionBase() noexcept override=default
int n_stacktrace_frames
Definition: exceptions.h:148
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
Definition: exceptions.cc:136
virtual void print_info(std::ostream &out) const
Definition: exceptions.cc:213
virtual const char * what() const noexcept override
Definition: exceptions.cc:161
const char * exc
Definition: exceptions.h:142
const char * function
Definition: exceptions.h:132
void print_exc_data(std::ostream &out) const
Definition: exceptions.cc:181
unsigned int line
Definition: exceptions.h:127
void * raw_stacktrace[25]
Definition: exceptions.h:154
const char * cond
Definition: exceptions.h:137
virtual void print_info(std::ostream &out) const override
Definition: exceptions.cc:388
ExcMPI(const int error_code)
Definition: exceptions.cc:383
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:457
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:458
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
#define DeclException0(Exception0)
Definition: exceptions.h:464
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcGridHasInvalidCell(int arg1)
static ::ExceptionBase & ExcCudaError(const char *arg1)
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
static ::ExceptionBase & ExcDivideByZero()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNeedsLAPACK()
static ::ExceptionBase & ExcNumberNotFinite(std::complex< double > arg1)
static ::ExceptionBase & ExcNeedsHDF5()
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcNeedsMPI()
static ::ExceptionBase & ExcFileNotOpen(std::string arg1)
static ::ExceptionBase & ExcOutOfMemory(std::size_t arg1)
static ::ExceptionBase & ExcNeedsAssimp()
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
static ::ExceptionBase & ExcPureFunctionCalled()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:532
static ::ExceptionBase & ExcEmptyObject()
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:487
static ::ExceptionBase & ExcMemoryLeak(int arg1)
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcIO()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:555
static ::ExceptionBase & ExcCusparseError(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:509
static ::ExceptionBase & ExcNeedsFunctionparser()
static ::ExceptionBase & ExcDimensionMismatch2(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
static ::ExceptionBase & ExcNeedsCGAL()
static ::ExceptionBase & ExcGhostsPresent()
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcNotMultiple(int arg1, int arg2)
static ::ExceptionBase & ExcNeedsExodusII()
static const char U
static const char T
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
std::string get_cusolver_error_string(const cusolverStatus_t error_code)
Definition: exceptions.cc:569
constexpr bool compare_less_than(const T &t, const U &u)
Definition: exceptions.h:1666
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
Definition: exceptions.cc:523
constexpr bool compare_for_equality(const T &t, const U &u)
Definition: exceptions.h:1652
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:1386
void abort(const ExceptionBase &exc) noexcept
Definition: exceptions.cc:460
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
Definition: exceptions.cc:506
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:1436
void enable_abort_on_exception()
Definition: exceptions.cc:89
void disable_abort_on_exception()
Definition: exceptions.cc:81
void set_additional_assert_output(const char *const p)
void suppress_stacktrace_in_exceptions()
Definition: exceptions.cc:73