Reference documentation for deal.II version Git eab6000ff4 2020-05-30 14:50:38 -0400
\(\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 - 2020 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 
49 class ExceptionBase : public std::exception
50 {
51 public:
55  ExceptionBase();
56 
61 
65  virtual ~ExceptionBase() noexcept override;
66 
72  operator=(const ExceptionBase &) = delete;
73 
79  void
80  set_fields(const char *file,
81  const int line,
82  const char *function,
83  const char *cond,
84  const char *exc_name);
85 
86 
90  virtual const char *
91  what() const noexcept override;
92 
96  const char *
97  get_exc_name() const;
98 
102  void
103  print_exc_data(std::ostream &out) const;
104 
109  virtual void
110  print_info(std::ostream &out) const;
111 
116  void
117  print_stack_trace(std::ostream &out) const;
118 
119 protected:
123  const char *file;
124 
128  unsigned int line;
129 
133  const char *function;
134 
138  const char *cond;
139 
143  const char *exc;
144 
149  mutable char **stacktrace;
150 
156 
157 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
158 
161  void *raw_stacktrace[25];
162 #endif
163 
164 private:
168  void
169  generate_message() const;
170 
175  mutable std::string what_str;
176 };
177 
178 #ifndef DOXYGEN
179 
197 # define DeclException0(Exception0) \
198  class Exception0 : public ::ExceptionBase \
199  {}
200 
201 
221 # define DeclExceptionMsg(Exception, defaulttext) \
222  class Exception : public ::ExceptionBase \
223  { \
224  public: \
225  Exception(const std::string &msg = defaulttext) \
226  : arg(msg) \
227  {} \
228  virtual ~Exception() noexcept \
229  {} \
230  virtual void \
231  print_info(std::ostream &out) const override \
232  { \
233  out << " " << arg << std::endl; \
234  } \
235  \
236  private: \
237  const std::string arg; \
238  }
239 
257 # define DeclException1(Exception1, type1, outsequence) \
258  class Exception1 : public ::ExceptionBase \
259  { \
260  public: \
261  Exception1(type1 const &a1) \
262  : arg1(a1) \
263  {} \
264  virtual ~Exception1() noexcept \
265  {} \
266  virtual void \
267  print_info(std::ostream &out) const override \
268  { \
269  out << " " outsequence << std::endl; \
270  } \
271  \
272  private: \
273  type1 const arg1; \
274  }
275 
276 
294 # define DeclException2(Exception2, type1, type2, outsequence) \
295  class Exception2 : public ::ExceptionBase \
296  { \
297  public: \
298  Exception2(type1 const &a1, type2 const &a2) \
299  : arg1(a1) \
300  , arg2(a2) \
301  {} \
302  virtual ~Exception2() noexcept \
303  {} \
304  virtual void \
305  print_info(std::ostream &out) const override \
306  { \
307  out << " " outsequence << std::endl; \
308  } \
309  \
310  private: \
311  type1 const arg1; \
312  type2 const arg2; \
313  }
314 
315 
333 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
334  class Exception3 : public ::ExceptionBase \
335  { \
336  public: \
337  Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \
338  : arg1(a1) \
339  , arg2(a2) \
340  , arg3(a3) \
341  {} \
342  virtual ~Exception3() noexcept \
343  {} \
344  virtual void \
345  print_info(std::ostream &out) const override \
346  { \
347  out << " " outsequence << std::endl; \
348  } \
349  \
350  private: \
351  type1 const arg1; \
352  type2 const arg2; \
353  type3 const arg3; \
354  }
355 
356 
374 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
375  class Exception4 : public ::ExceptionBase \
376  { \
377  public: \
378  Exception4(type1 const &a1, \
379  type2 const &a2, \
380  type3 const &a3, \
381  type4 const &a4) \
382  : arg1(a1) \
383  , arg2(a2) \
384  , arg3(a3) \
385  , arg4(a4) \
386  {} \
387  virtual ~Exception4() noexcept \
388  {} \
389  virtual void \
390  print_info(std::ostream &out) const override \
391  { \
392  out << " " outsequence << std::endl; \
393  } \
394  \
395  private: \
396  type1 const arg1; \
397  type2 const arg2; \
398  type3 const arg3; \
399  type4 const arg4; \
400  }
401 
402 
420 # define DeclException5( \
421  Exception5, type1, type2, type3, type4, type5, outsequence) \
422  class Exception5 : public ::ExceptionBase \
423  { \
424  public: \
425  Exception5(type1 const &a1, \
426  type2 const &a2, \
427  type3 const &a3, \
428  type4 const &a4, \
429  type5 const &a5) \
430  : arg1(a1) \
431  , arg2(a2) \
432  , arg3(a3) \
433  , arg4(a4) \
434  , arg5(a5) \
435  {} \
436  virtual ~Exception5() noexcept \
437  {} \
438  virtual void \
439  print_info(std::ostream &out) const override \
440  { \
441  out << " " outsequence << std::endl; \
442  } \
443  \
444  private: \
445  type1 const arg1; \
446  type2 const arg2; \
447  type3 const arg3; \
448  type4 const arg4; \
449  type5 const arg5; \
450  }
451 
452 #else /*ifndef DOXYGEN*/
453 
454 // Dummy definitions for doxygen:
455 
473 # define DeclException0(Exception0) \
474  \
475  static ::ExceptionBase &Exception0()
476 
496 # define DeclExceptionMsg(Exception, defaulttext) \
497  \
498  \
499  static ::ExceptionBase &Exception()
500 
518 # define DeclException1(Exception1, type1, outsequence) \
519  \
520  \
521  static ::ExceptionBase &Exception1(type1 arg1)
522 
523 
541 # define DeclException2(Exception2, type1, type2, outsequence) \
542  \
543  \
544  static ::ExceptionBase &Exception2(type1 arg1, type2 arg2)
545 
546 
564 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
565  \
566  \
567  static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3)
568 
569 
587 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
588  \
589  \
590  static ::ExceptionBase &Exception4(type1 arg1, \
591  type2 arg2, \
592  type3 arg3, \
593  type4 arg4)
594 
595 
613 # define DeclException5( \
614  Exception5, type1, type2, type3, type4, type5, outsequence) \
615  \
616  \
617  static ::ExceptionBase &Exception5( \
618  type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)
619 
620 #endif /*ifndef DOXYGEN*/
621 
622 
635 {
640 
645  "A piece of code is attempting a division by zero. This is "
646  "likely going to lead to results that make no sense.");
647 
660  std::complex<double>,
661  << "In a significant number of places, deal.II checks that some intermediate "
662  << "value is a finite number (as opposed to plus or minus infinity, or "
663  << "NaN/Not a Number). In the current function, we encountered a number "
664  << "that is not finite (its value is " << arg1 << " and therefore "
665  << "violates the current assertion).\n\n"
666  << "This may be due to the fact that some operation in this function "
667  << "created such a value, or because one of the arguments you passed "
668  << "to the function already had this value from some previous "
669  << "operation. In the latter case, this function only triggered the "
670  << "error but may not actually be responsible for the computation of "
671  << "the number that is not finite.\n\n"
672  << "There are two common cases where this situation happens. First, your "
673  << "code (or something in deal.II) divides by zero in a place where this "
674  << "should not happen. Or, you are trying to solve a linear system "
675  << "with an unsuitable solver (such as an indefinite or non-symmetric "
676  << "linear system using a Conjugate Gradient solver); such attempts "
677  << "oftentimes yield an operation somewhere that tries to divide "
678  << "by zero or take the square root of a negative value.\n\n"
679  << "In any case, when trying to find the source of the error, "
680  << "recall that the location where you are getting this error is "
681  << "simply the first place in the program where there is a check "
682  << "that a number (e.g., an element of a solution vector) is in fact "
683  << "finite, but that the actual error that computed the number "
684  << "may have happened far earlier. To find this location, you "
685  << "may want to add checks for finiteness in places of your "
686  << "program visited before the place where this error is produced. "
687  << "One way to check for finiteness is to use the 'AssertIsFinite' "
688  << "macro.");
689 
694  std::size_t,
695  "Your program tried to allocate some memory but this "
696  "allocation failed. Typically, this either means that "
697  "you simply do not have enough memory in your system, "
698  "or that you are (erroneously) trying to allocate "
699  "a chunk of memory that is simply beyond all reasonable "
700  "size, for example because the size of the object has "
701  "been computed incorrectly."
702  "\n\n"
703  "In the current case, the request was for "
704  << arg1 << " bytes.");
705 
711  int,
712  << "Destroying memory handler while " << arg1
713  << " objects are still allocated.");
714 
719  "An input/output error has occurred. There are a number of "
720  "reasons why this may be happening, both for reading and "
721  "writing operations."
722  "\n\n"
723  "If this happens during an operation that tries to read "
724  "data: First, you may be "
725  "trying to read from a file that doesn't exist or that is "
726  "not readable given its file permissions. Second, deal.II "
727  "uses this error at times if it tries to "
728  "read information from a file but where the information "
729  "in the file does not correspond to the expected format. "
730  "An example would be a truncated file, or a mesh file "
731  "that contains not only sections that describe the "
732  "vertices and cells, but also sections for additional "
733  "data that deal.II does not understand."
734  "\n\n"
735  "If this happens during an operation that tries to write "
736  "data: you may be trying to write to a file to which file "
737  "or directory permissions do not allow you to write. A "
738  "typical example is where you specify an output file in "
739  "a directory that does not exist.");
740 
748  std::string,
749  << "Could not open file " << arg1 << ".");
750 
760  "You are trying to use functionality in deal.II that is "
761  "currently not implemented. In many cases, this indicates "
762  "that there simply didn't appear much of a need for it, or "
763  "that the author of the original code did not have the "
764  "time to implement a particular case. If you hit this "
765  "exception, it is therefore worth the time to look into "
766  "the code to find out whether you may be able to "
767  "implement the missing functionality. If you do, please "
768  "consider providing a patch to the deal.II development "
769  "sources (see the deal.II website on how to contribute).");
770 
792  "This exception -- which is used in many places in the "
793  "library -- usually indicates that some condition which "
794  "the author of the code thought must be satisfied at a "
795  "certain point in an algorithm, is not fulfilled. An "
796  "example would be that the first part of an algorithm "
797  "sorts elements of an array in ascending order, and "
798  "a second part of the algorithm later encounters an "
799  "element that is not larger than the previous one."
800  "\n\n"
801  "There is usually not very much you can do if you "
802  "encounter such an exception since it indicates an error "
803  "in deal.II, not in your own program. Try to come up with "
804  "the smallest possible program that still demonstrates "
805  "the error and contact the deal.II mailing lists with it "
806  "to obtain help.");
807 
816  "You (or a place in the library) are trying to call a "
817  "function that is declared as a virtual function in a "
818  "base class but that has not been overridden in your "
819  "derived class."
820  "\n\n"
821  "This exception happens in cases where the base class "
822  "cannot provide a useful default implementation for "
823  "the virtual function, but where we also do not want "
824  "to mark the function as abstract (i.e., with '=0' at the end) "
825  "because the function is not essential to the class in many "
826  "contexts. In cases like this, the base class provides "
827  "a dummy implementation that makes the compiler happy, but "
828  "that then throws the current exception."
829  "\n\n"
830  "A concrete example would be the 'Function' class. It declares "
831  "the existence of 'value()' and 'gradient()' member functions, "
832  "and both are marked as 'virtual'. Derived classes have to "
833  "override these functions for the values and gradients of a "
834  "particular function. On the other hand, not every function "
835  "has a gradient, and even for those that do, not every program "
836  "actually needs to evaluate it. Consequently, there is no "
837  "*requirement* that a derived class actually override the "
838  "'gradient()' function (as there would be had it been marked "
839  "as abstract). But, since the base class cannot know how to "
840  "compute the gradient, if a derived class does not override "
841  "the 'gradient()' function and it is called anyway, then the "
842  "default implementation in the base class will simply throw "
843  "an exception."
844  "\n\n"
845  "The exception you see is what happens in cases such as the "
846  "one just illustrated. To fix the problem, you need to "
847  "investigate whether the function being called should indeed have "
848  "been called; if the answer is 'yes', then you need to "
849  "implement the missing override in your class.");
850 
855 
860 
868  int,
869  << "You are trying to execute functionality that is "
870  << "impossible in " << arg1
871  << "d or simply does not make any sense.");
872 
881  int,
882  int,
883  << "You are trying to execute functionality that is "
884  << "impossible in dimensions <" << arg1 << "," << arg2
885  << "> or simply does not make any sense.");
886 
887 
892  "In a check in the code, deal.II encountered a zero in "
893  "a place where this does not make sense. See the condition "
894  "that was being checked and that is printed further up "
895  "in the error message to get more information on what "
896  "the erroneous zero corresponds to.");
897 
903  "The object you are trying to access is empty but it makes "
904  "no sense to attempt the operation you are trying on an "
905  "empty object.");
906 
915  std::size_t,
916  std::size_t,
917  << "Dimension " << arg1 << " not equal to " << arg2 << ".");
918 
924  int,
925  int,
926  int,
927  << "Dimension " << arg1 << " neither equal to " << arg2
928  << " nor to " << arg3 << ".");
929 
944  int,
945  int,
946  int,
947  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ","
948  << arg3 << ")."
949  << (arg2 == arg3 ?
950  " In the current case, this half-open range is in fact empty, "
951  "suggesting that you are accessing an element of an empty "
952  "collection such as a vector that has not been set to the "
953  "correct size." :
954  ""));
955 
971  template <typename T>
974  T,
975  T,
976  T,
977  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ","
978  << arg3 << ")."
979  << (arg2 == arg3 ?
980  " In the current case, this half-open range is in fact empty, "
981  "suggesting that you are accessing an element of an empty "
982  "collection such as a vector that has not been set to the "
983  "correct size." :
984  ""));
985 
990  int,
991  int,
992  << "Number " << arg1 << " must be larger than or equal "
993  << arg2 << ".");
994 
998  template <typename T>
1000  T,
1001  T,
1002  << "Number " << arg1 << " must be larger than or equal "
1003  << arg2 << ".");
1004 
1010  int,
1011  int,
1012  << "Division " << arg1 << " by " << arg2
1013  << " has remainder different from zero.");
1014 
1024  "You are trying to use an iterator, but the iterator is "
1025  "in an invalid state. This may indicate that the iterator "
1026  "object has not been initialized, or that it has been "
1027  "moved beyond the end of the range of valid elements.");
1028 
1034  "You are trying to use an iterator, but the iterator is "
1035  "pointing past the end of the range of valid elements. "
1036  "It is not valid to dereference the iterator in this "
1037  "case.");
1038 
1052  DeclException1(ExcMessage, std::string, << arg1);
1053 
1058  "You are trying an operation on a vector that is only "
1059  "allowed if the vector has no ghost elements, but the "
1060  "vector you are operating on does have ghost elements. "
1061  "Specifically, vectors with ghost elements are read-only "
1062  "and cannot appear in operations that write into these "
1063  "vectors."
1064  "\n\n"
1065  "See the glossary entry on 'Ghosted vectors' for more "
1066  "information.");
1067 
1076  "You are trying an operation of the form 'vector=s' with "
1077  "a nonzero scalar value 's'. However, such assignments "
1078  "are only allowed if the right hand side is zero.");
1079 
1085  "You are attempting to use functionality that is only available "
1086  "if deal.II was configured to use LAPACK, but cmake did not "
1087  "find a valid LAPACK library.");
1088 
1093  ExcNeedsMPI,
1094  "You are attempting to use functionality that is only available "
1095  "if deal.II was configured to use MPI.");
1096 
1102  "You are attempting to use functionality that is only available "
1103  "if deal.II was configured to use the function parser which "
1104  "relies on the muparser library, but cmake did not "
1105  "find a valid muparser library on your system and also did "
1106  "not choose the one that comes bundled with deal.II.");
1107 
1113  "You are attempting to use functionality that is only available "
1114  "if deal.II was configured to use Assimp, but cmake did not "
1115  "find a valid Assimp library.");
1116 
1117 #ifdef DEAL_II_WITH_CUDA
1118 
1124  DeclException1(ExcCudaError, const char *, << arg1);
1129  std::string,
1130  << "There was an error in a cuSPARSE function: " << arg1);
1131 #endif
1132 
1133 
1134 #ifdef DEAL_II_WITH_MPI
1135 
1157  class ExcMPI : public ::ExceptionBase
1158  {
1159  public:
1160  ExcMPI(const int error_code);
1161 
1162  virtual void
1163  print_info(std::ostream &out) const override;
1164 
1165  const int error_code;
1166  };
1167 #endif // DEAL_II_WITH_MPI
1168 } /*namespace StandardExceptions*/
1169 
1170 
1171 
1179 {
1180  namespace internals
1181  {
1189  extern bool allow_abort_on_exception;
1190  } // namespace internals
1191 
1210  void
1211  set_additional_assert_output(const char *const p);
1212 
1223  void
1225 
1239  void
1241 
1249  namespace internals
1250  {
1255  [[noreturn]] void
1256  abort(const ExceptionBase &exc) noexcept;
1257 
1262  {
1273  };
1274 
1292  template <class ExceptionType>
1293  [[noreturn]] void
1295  const char * file,
1296  int line,
1297  const char * function,
1298  const char * cond,
1299  const char * exc_name,
1300  ExceptionType e) {
1301  // Fill the fields of the exception object
1302  e.set_fields(file, line, function, cond, exc_name);
1303 
1304  switch (handling)
1305  {
1307  {
1310  internals::abort(e);
1311  else
1312  {
1313  // We are not allowed to abort, so just throw the error:
1314  throw e;
1315  }
1316  }
1317  case throw_on_exception:
1318  throw e;
1319  // this function should never return (and AssertNothrow can);
1320  // something must have gone wrong in the error handling code for us
1321  // to get this far, so throw an exception.
1322  default:
1324  }
1325  }
1326 
1330  void do_issue_error_nothrow(const ExceptionBase &e) noexcept;
1331 
1340  template <class ExceptionType>
1341  void
1343  int line,
1344  const char * function,
1345  const char * cond,
1346  const char * exc_name,
1347  ExceptionType e) noexcept
1348  {
1350  "The provided exception must inherit from ExceptionBase.");
1351  // Fill the fields of the exception object
1352  e.set_fields(file, line, function, cond, exc_name);
1353  // avoid moving a bunch of code into the header by dispatching to
1354  // another function:
1356  }
1357 #ifdef DEAL_II_WITH_CUDA
1358 
1363  std::string
1364  get_cusparse_error_string(const cusparseStatus_t error_code);
1365 
1371  std::string
1372  get_cusolver_error_string(const cusolverStatus_t error_code);
1373 #endif
1374  } /*namespace internals*/
1375 
1376 } /*namespace deal_II_exceptions*/
1377 
1378 
1379 
1406 #ifdef DEBUG
1407 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1408 # define Assert(cond, exc) \
1409  { \
1410  if (__builtin_expect(!(cond), false)) \
1411  ::deal_II_exceptions::internals::issue_error_noreturn( \
1412  ::deal_II_exceptions::internals:: \
1413  abort_or_throw_on_exception, \
1414  __FILE__, \
1415  __LINE__, \
1416  __PRETTY_FUNCTION__, \
1417  #cond, \
1418  #exc, \
1419  exc); \
1420  }
1421 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1422 # define Assert(cond, exc) \
1423  { \
1424  if (!(cond)) \
1425  ::deal_II_exceptions::internals::issue_error_noreturn( \
1426  ::deal_II_exceptions::internals:: \
1427  abort_or_throw_on_exception, \
1428  __FILE__, \
1429  __LINE__, \
1430  __PRETTY_FUNCTION__, \
1431  #cond, \
1432  #exc, \
1433  exc); \
1434  }
1435 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1436 #else
1437 # define Assert(cond, exc) \
1438  {}
1439 #endif
1440 
1441 
1442 
1470 #ifdef DEBUG
1471 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1472 # define AssertNothrow(cond, exc) \
1473  { \
1474  if (__builtin_expect(!(cond), false)) \
1475  ::deal_II_exceptions::internals::issue_error_nothrow( \
1476  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1477  }
1478 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1479 # define AssertNothrow(cond, exc) \
1480  { \
1481  if (!(cond)) \
1482  ::deal_II_exceptions::internals::issue_error_nothrow( \
1483  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1484  }
1485 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1486 #else
1487 # define AssertNothrow(cond, exc) \
1488  {}
1489 #endif
1490 
1519 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1520 # define AssertThrow(cond, exc) \
1521  { \
1522  if (__builtin_expect(!(cond), false)) \
1523  ::deal_II_exceptions::internals::issue_error_noreturn( \
1524  ::deal_II_exceptions::internals::throw_on_exception, \
1525  __FILE__, \
1526  __LINE__, \
1527  __PRETTY_FUNCTION__, \
1528  #cond, \
1529  #exc, \
1530  exc); \
1531  }
1532 #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1533 # define AssertThrow(cond, exc) \
1534  { \
1535  if (!(cond)) \
1536  ::deal_II_exceptions::internals::issue_error_noreturn( \
1537  ::deal_II_exceptions::internals::throw_on_exception, \
1538  __FILE__, \
1539  __LINE__, \
1540  __PRETTY_FUNCTION__, \
1541  #cond, \
1542  #exc, \
1543  exc); \
1544  }
1545 #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1546 
1568 #define AssertDimension(dim1, dim2) \
1569  Assert(static_cast<typename ::internal::argument_type<void( \
1570  typename std::common_type<decltype(dim1), \
1571  decltype(dim2)>::type)>::type>(dim1) == \
1572  static_cast<typename ::internal::argument_type<void( \
1573  typename std::common_type<decltype(dim1), \
1574  decltype(dim2)>::type)>::type>(dim2), \
1575  ::ExcDimensionMismatch((dim1), (dim2)))
1576 
1577 
1596 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \
1597  AssertDimension(VEC.size(), DIM1); \
1598  for (const auto &subvector : VEC) \
1599  { \
1600  (void)subvector; \
1601  AssertDimension(subvector.size(), DIM2); \
1602  }
1603 
1604 namespace internal
1605 {
1606  // Workaround to allow for commas in template parameter lists
1607  // in preprocessor macros as found in
1608  // https://stackoverflow.com/questions/13842468/comma-in-c-c-macro
1609  template <typename T>
1611  template <typename T, typename U>
1612  struct argument_type<T(U)>
1613  {
1614  using type = U;
1615  };
1616 } // namespace internal
1617 
1638 #define AssertIndexRange(index, range) \
1639  Assert( \
1640  static_cast<typename ::internal::argument_type<void( \
1641  typename std::common_type<decltype(index), decltype(range)>::type)>:: \
1642  type>(index) < \
1643  static_cast<typename ::internal::argument_type<void( \
1644  typename std::common_type<decltype(index), decltype(range)>::type)>:: \
1645  type>(range), \
1646  ExcIndexRangeType<typename ::internal::argument_type<void( \
1647  typename std::common_type<decltype(index), decltype(range)>::type)>:: \
1648  type>((index), 0, (range)))
1649 
1670 #define AssertIsFinite(number) \
1671  Assert(::numbers::is_finite(number), \
1672  ::ExcNumberNotFinite(std::complex<double>(number)))
1673 
1674 #ifdef DEAL_II_WITH_MPI
1675 
1696 # define AssertThrowMPI(error_code) \
1697  AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code))
1698 #else
1699 # define AssertThrowMPI(error_code) \
1700  {}
1701 #endif // DEAL_II_WITH_MPI
1702 
1703 #ifdef DEAL_II_WITH_CUDA
1704 
1722 # ifdef DEBUG
1723 # define AssertCuda(error_code) \
1724  Assert(error_code == cudaSuccess, \
1725  ::ExcCudaError(cudaGetErrorString(error_code)))
1726 # else
1727 # define AssertCuda(error_code) \
1728  { \
1729  (void)(error_code); \
1730  }
1731 # endif
1732 
1750 # ifdef DEBUG
1751 # define AssertNothrowCuda(error_code) \
1752  AssertNothrow(error_code == cudaSuccess, \
1753  ::ExcCudaError(cudaGetErrorString(error_code)))
1754 # else
1755 # define AssertNothrowCuda(error_code) \
1756  { \
1757  (void)(error_code); \
1758  }
1759 # endif
1760 
1779 # ifdef DEBUG
1780 # define AssertCudaKernel() \
1781  { \
1782  cudaError_t local_error_code = cudaPeekAtLastError(); \
1783  AssertCuda(local_error_code); \
1784  local_error_code = cudaDeviceSynchronize(); \
1785  AssertCuda(local_error_code) \
1786  }
1787 # else
1788 # define AssertCudaKernel() \
1789  {}
1790 # endif
1791 
1810 # ifdef DEBUG
1811 # define AssertCusparse(error_code) \
1812  Assert( \
1813  error_code == CUSPARSE_STATUS_SUCCESS, \
1814  ExcCusparseError( \
1815  deal_II_exceptions::internals::get_cusparse_error_string( \
1816  error_code)))
1817 # else
1818 # define AssertCusparse(error_code) \
1819  { \
1820  (void)(error_code); \
1821  }
1822 # endif
1823 
1841 # ifdef DEBUG
1842 # define AssertNothrowCusparse(error_code) \
1843  AssertNothrow( \
1844  error_code == CUSPARSE_STATUS_SUCCESS, \
1845  ExcCusparseError( \
1846  deal_II_exceptions::internals::get_cusparse_error_string( \
1847  error_code)))
1848 # else
1849 # define AssertNothrowCusparse(error_code) \
1850  { \
1851  (void)(error_code); \
1852  }
1853 # endif
1854 
1873 # ifdef DEBUG
1874 # define AssertCusolver(error_code) \
1875  Assert( \
1876  error_code == CUSOLVER_STATUS_SUCCESS, \
1877  ExcCusparseError( \
1878  deal_II_exceptions::internals::get_cusolver_error_string( \
1879  error_code)))
1880 # else
1881 # define AssertCusolver(error_code) \
1882  { \
1883  (void)(error_code); \
1884  }
1885 # endif
1886 
1887 #endif
1888 
1889 using namespace StandardExceptions;
1890 
1892 
1893 #endif
static ::ExceptionBase & ExcCudaError(const char *arg1)
static ::ExceptionBase & ExcPureFunctionCalled()
static ::ExceptionBase & ExcNeedsFunctionparser()
static ::ExceptionBase & ExcNeedsMPI()
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
void suppress_stacktrace_in_exceptions()
Definition: exceptions.cc:65
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:115
std::string get_cusolver_error_string(const cusolverStatus_t error_code)
Definition: exceptions.cc:517
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:161
virtual void print_info(std::ostream &out) const
Definition: exceptions.cc:210
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:147
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:518
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:124
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
Definition: exceptions.cc:454
static ::ExceptionBase & ExcOutOfMemory(std::size_t arg1)
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
Definition: exceptions.cc:471
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:496
#define DeclException0(Exception0)
Definition: exceptions.h:473
void abort(const ExceptionBase &exc) noexcept
Definition: exceptions.cc:408
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:361
static ::ExceptionBase & ExcNeedsAssimp()
static ::ExceptionBase & ExcIndexRangeType(T arg1, T arg2, T arg3)
std::string what_str
Definition: exceptions.h:175
unsigned int line
Definition: exceptions.h:128
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
void print_stack_trace(std::ostream &out) const
Definition: exceptions.cc:218
static ::ExceptionBase & ExcGhostsPresent()
static ::ExceptionBase & ExcIteratorPastEnd()
const char * exc
Definition: exceptions.h:143
const char * cond
Definition: exceptions.h:138
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:1294
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:1342
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:360
const char * file
Definition: exceptions.h:123
static ::ExceptionBase & ExcCusparseError(std::string arg1)
static ::ExceptionBase & ExcEmptyObject()
void print_exc_data(std::ostream &out) const
Definition: exceptions.cc:178
static ::ExceptionBase & ExcNotMultiple(int arg1, int arg2)
static ::ExceptionBase & ExcNotImplemented()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:564
void generate_message() const
Definition: exceptions.cc:307
char ** stacktrace
Definition: exceptions.h:149
void disable_abort_on_exception()
Definition: exceptions.cc:71
static const bool value
const char * get_exc_name() const
Definition: exceptions.cc:170
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcFileNotOpen(std::string arg1)
int n_stacktrace_frames
Definition: exceptions.h:155
static ::ExceptionBase & ExcLowerRangeType(T arg1, T arg2)
static ::ExceptionBase & ExcInternalError()