Reference documentation for deal.II version GIT 9042b9283b 2023-12-02 14:50: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 - 2023 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 
22 #include <Kokkos_Macros.hpp>
23 #if KOKKOS_VERSION >= 40200
24 # include <Kokkos_Abort.hpp>
25 #else
26 # include <Kokkos_Core.hpp>
27 #endif
29 
30 #include <exception>
31 #include <ostream>
32 #include <string>
33 #include <type_traits>
34 
35 #ifdef DEAL_II_WITH_CUDA
36 # include <cusolverSp.h>
37 # include <cusparse.h>
38 #endif
39 
41 
42 
56 class ExceptionBase : public std::exception
57 {
58 public:
62  ExceptionBase();
63 
68 
72  virtual ~ExceptionBase() noexcept override = default;
73 
79  operator=(const ExceptionBase &) = delete;
80 
86  void
87  set_fields(const char *file,
88  const int line,
89  const char *function,
90  const char *cond,
91  const char *exc_name);
92 
93 
97  virtual const char *
98  what() const noexcept override;
99 
103  const char *
104  get_exc_name() const;
105 
109  void
110  print_exc_data(std::ostream &out) const;
111 
116  virtual void
117  print_info(std::ostream &out) const;
118 
123  void
124  print_stack_trace(std::ostream &out) const;
125 
126 protected:
130  const char *file;
131 
135  unsigned int line;
136 
140  const char *function;
141 
145  const char *cond;
146 
150  const char *exc;
151 
157 
158 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
162  void *raw_stacktrace[25];
163 #endif
164 
165 private:
169  void
170  generate_message() const;
171 
176  mutable std::string what_str;
177 };
178 
179 #ifndef DOXYGEN
180 
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 
472 # define DeclException0(Exception0) \
473  \
474  static ::ExceptionBase &Exception0()
475 
495 # define DeclExceptionMsg(Exception, defaulttext) \
496  \
497  \
498  static ::ExceptionBase &Exception()
499 
517 # define DeclException1(Exception1, type1, outsequence) \
518  \
519  \
520  static ::ExceptionBase &Exception1(type1 arg1)
521 
522 
540 # define DeclException2(Exception2, type1, type2, outsequence) \
541  \
542  \
543  static ::ExceptionBase &Exception2(type1 arg1, type2 arg2)
544 
545 
563 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
564  \
565  \
566  static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3)
567 
568 
586 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
587  \
588  \
589  static ::ExceptionBase &Exception4(type1 arg1, \
590  type2 arg2, \
591  type3 arg3, \
592  type4 arg4)
593 
594 
612 # define DeclException5( \
613  Exception5, type1, type2, type3, type4, type5, outsequence) \
614  \
615  \
616  static ::ExceptionBase &Exception5( \
617  type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)
618 
619 #endif /*ifndef DOXYGEN*/
620 
621 
634 {
644  "A piece of code is attempting a division by zero. This is "
645  "likely going to lead to results that make no sense.");
646 
659  std::complex<double>,
660  << "In a significant number of places, deal.II checks that some intermediate "
661  << "value is a finite number (as opposed to plus or minus infinity, or "
662  << "NaN/Not a Number). In the current function, we encountered a number "
663  << "that is not finite (its value is " << arg1 << " and therefore "
664  << "violates the current assertion).\n\n"
665  << "This may be due to the fact that some operation in this function "
666  << "created such a value, or because one of the arguments you passed "
667  << "to the function already had this value from some previous "
668  << "operation. In the latter case, this function only triggered the "
669  << "error but may not actually be responsible for the computation of "
670  << "the number that is not finite.\n\n"
671  << "There are two common cases where this situation happens. First, your "
672  << "code (or something in deal.II) divides by zero in a place where this "
673  << "should not happen. Or, you are trying to solve a linear system "
674  << "with an unsuitable solver (such as an indefinite or non-symmetric "
675  << "linear system using a Conjugate Gradient solver); such attempts "
676  << "oftentimes yield an operation somewhere that tries to divide "
677  << "by zero or take the square root of a negative value.\n\n"
678  << "In any case, when trying to find the source of the error, "
679  << "recall that the location where you are getting this error is "
680  << "simply the first place in the program where there is a check "
681  << "that a number (e.g., an element of a solution vector) is in fact "
682  << "finite, but that the actual error that computed the number "
683  << "may have happened far earlier. To find this location, you "
684  << "may want to add checks for finiteness in places of your "
685  << "program visited before the place where this error is produced. "
686  << "One way to check for finiteness is to use the 'AssertIsFinite' "
687  << "macro.");
688 
693  std::size_t,
694  "Your program tried to allocate some memory but this "
695  "allocation failed. Typically, this either means that "
696  "you simply do not have enough memory in your system, "
697  "or that you are (erroneously) trying to allocate "
698  "a chunk of memory that is simply beyond all reasonable "
699  "size, for example because the size of the object has "
700  "been computed incorrectly."
701  "\n\n"
702  "In the current case, the request was for "
703  << arg1 << " bytes.");
704 
710  int,
711  << "Destroying memory handler while " << arg1
712  << " objects are still allocated.");
713 
718  "An input/output error has occurred. There are a number of "
719  "reasons why this may be happening, both for reading and "
720  "writing operations."
721  "\n\n"
722  "If this happens during an operation that tries to read "
723  "data: First, you may be "
724  "trying to read from a file that doesn't exist or that is "
725  "not readable given its file permissions. Second, deal.II "
726  "uses this error at times if it tries to "
727  "read information from a file but where the information "
728  "in the file does not correspond to the expected format. "
729  "An example would be a truncated file, or a mesh file "
730  "that contains not only sections that describe the "
731  "vertices and cells, but also sections for additional "
732  "data that deal.II does not understand."
733  "\n\n"
734  "If this happens during an operation that tries to write "
735  "data: you may be trying to write to a file to which file "
736  "or directory permissions do not allow you to write. A "
737  "typical example is where you specify an output file in "
738  "a directory that does not exist.");
739 
747  std::string,
748  << "Could not open file " << arg1
749  << "."
750  "\n\n"
751  "If this happens during an operation that tries to read "
752  "data: you may be "
753  "trying to read from a file that doesn't exist or that is "
754  "not readable given its file permissions."
755  "\n\n"
756  "If this happens during an operation that tries to write "
757  "data: you may be trying to write to a file to which file "
758  "or directory permissions do not allow you to write. A "
759  "typical example is where you specify an output file in "
760  "a directory that does not exist.");
761 
771  "You are trying to use functionality in deal.II that is "
772  "currently not implemented. In many cases, this indicates "
773  "that there simply didn't appear much of a need for it, or "
774  "that the author of the original code did not have the "
775  "time to implement a particular case. If you hit this "
776  "exception, it is therefore worth the time to look into "
777  "the code to find out whether you may be able to "
778  "implement the missing functionality. If you do, please "
779  "consider providing a patch to the deal.II development "
780  "sources (see the deal.II website on how to contribute).");
781 
803  "This exception -- which is used in many places in the "
804  "library -- usually indicates that some condition which "
805  "the author of the code thought must be satisfied at a "
806  "certain point in an algorithm, is not fulfilled. An "
807  "example would be that the first part of an algorithm "
808  "sorts elements of an array in ascending order, and "
809  "a second part of the algorithm later encounters an "
810  "element that is not larger than the previous one."
811  "\n\n"
812  "There is usually not very much you can do if you "
813  "encounter such an exception since it indicates an error "
814  "in deal.II, not in your own program. Try to come up with "
815  "the smallest possible program that still demonstrates "
816  "the error and contact the deal.II mailing lists with it "
817  "to obtain help.");
818 
827  "You (or a place in the library) are trying to call a "
828  "function that is declared as a virtual function in a "
829  "base class but that has not been overridden in your "
830  "derived class."
831  "\n\n"
832  "This exception happens in cases where the base class "
833  "cannot provide a useful default implementation for "
834  "the virtual function, but where we also do not want "
835  "to mark the function as abstract (i.e., with '=0' at the end) "
836  "because the function is not essential to the class in many "
837  "contexts. In cases like this, the base class provides "
838  "a dummy implementation that makes the compiler happy, but "
839  "that then throws the current exception."
840  "\n\n"
841  "A concrete example would be the 'Function' class. It declares "
842  "the existence of 'value()' and 'gradient()' member functions, "
843  "and both are marked as 'virtual'. Derived classes have to "
844  "override these functions for the values and gradients of a "
845  "particular function. On the other hand, not every function "
846  "has a gradient, and even for those that do, not every program "
847  "actually needs to evaluate it. Consequently, there is no "
848  "*requirement* that a derived class actually override the "
849  "'gradient()' function (as there would be had it been marked "
850  "as abstract). But, since the base class cannot know how to "
851  "compute the gradient, if a derived class does not override "
852  "the 'gradient()' function and it is called anyway, then the "
853  "default implementation in the base class will simply throw "
854  "an exception."
855  "\n\n"
856  "The exception you see is what happens in cases such as the "
857  "one just illustrated. To fix the problem, you need to "
858  "investigate whether the function being called should indeed have "
859  "been called; if the answer is 'yes', then you need to "
860  "implement the missing override in your class.");
861 
866  std::string,
867  << "Please provide an implementation for the function \""
868  << arg1 << "\"");
869 
875  std::string,
876  int,
877  << "The function \"" << arg1 << "\" returned the nonzero value " << arg2
878  << ", but the calling site expected the return value to be zero. "
879  "This error often happens when the function in question is a 'callback', "
880  "that is a user-provided function called from somewhere within deal.II "
881  "or within an external library such as PETSc, Trilinos, SUNDIALS, etc., "
882  "that expect these callbacks to indicate errors via nonzero return "
883  "codes.");
884 
889 
894 
902  int,
903  << "You are trying to execute functionality that is "
904  << "impossible in " << arg1
905  << "d or simply does not make any sense.");
906 
915  int,
916  int,
917  << "You are trying to execute functionality that is "
918  << "impossible in dimensions <" << arg1 << ',' << arg2
919  << "> or simply does not make any sense.");
920 
921 
926  "In a check in the code, deal.II encountered a zero in "
927  "a place where this does not make sense. See the condition "
928  "that was being checked and that is printed further up "
929  "in the error message to get more information on what "
930  "the erroneous zero corresponds to.");
931 
937  "The object you are trying to access is empty but it makes "
938  "no sense to attempt the operation you are trying on an "
939  "empty object.");
940 
949  std::size_t,
950  std::size_t,
951  << "Two sizes or dimensions were supposed to be equal, "
952  << "but aren't. They are " << arg1 << " and " << arg2 << '.');
953 
959  std::size_t,
960  std::size_t,
961  std::size_t,
962  << "The size or dimension of one object, " << arg1
963  << " was supposed to be "
964  << "equal to one of two values, but isn't. The two possible "
965  << "values are " << arg2 << " and " << arg3 << '.');
966 
981  std::size_t,
982  std::size_t,
983  std::size_t,
984  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
985  << arg3 << ")."
986  << (arg2 == arg3 ?
987  " In the current case, this half-open range is in fact empty, "
988  "suggesting that you are accessing an element of an empty "
989  "collection such as a vector that has not been set to the "
990  "correct size." :
991  ""));
992 
1008  template <typename T>
1011  T,
1012  T,
1013  T,
1014  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
1015  << arg3 << ")."
1016  << (arg2 == arg3 ?
1017  " In the current case, this half-open range is in fact empty, "
1018  "suggesting that you are accessing an element of an empty "
1019  "collection such as a vector that has not been set to the "
1020  "correct size." :
1021  ""));
1022 
1027  int,
1028  int,
1029  << "Number " << arg1 << " must be larger than or equal "
1030  << arg2 << '.');
1031 
1035  template <typename T>
1037  T,
1038  T,
1039  << "Number " << arg1 << " must be larger than or equal "
1040  << arg2 << '.');
1041 
1047  int,
1048  int,
1049  << "Division " << arg1 << " by " << arg2
1050  << " has remainder different from zero.");
1051 
1061  "You are trying to use an iterator, but the iterator is "
1062  "in an invalid state. This may indicate that the iterator "
1063  "object has not been initialized, or that it has been "
1064  "moved beyond the end of the range of valid elements.");
1065 
1071  "You are trying to use an iterator, but the iterator is "
1072  "pointing past the end of the range of valid elements. "
1073  "It is not valid to dereference the iterator in this "
1074  "case.");
1075 
1089  DeclException1(ExcMessage, std::string, << arg1);
1090 
1095  "You are trying an operation on a vector that is only "
1096  "allowed if the vector has no ghost elements, but the "
1097  "vector you are operating on does have ghost elements. "
1098  "Specifically, vectors with ghost elements are read-only "
1099  "and cannot appear in operations that write into these "
1100  "vectors."
1101  "\n\n"
1102  "See the glossary entry on 'Ghosted vectors' for more "
1103  "information.");
1104 
1110  int,
1111  << "Something went wrong when making cell " << arg1
1112  << ". Read the docs and the source code "
1113  << "for more information.");
1114 
1123  "You are trying an operation of the form 'vector = C', "
1124  "'matrix = C', or 'tensor = C' with a nonzero scalar value "
1125  "'C'. However, such assignments are only allowed if the "
1126  "C is zero, since the semantics for assigning any other "
1127  "value are not clear. For example: one could interpret "
1128  "assigning a matrix a value of 1 to mean the matrix has a "
1129  "norm of 1, the matrix is the identity matrix, or the "
1130  "matrix contains only 1s. Similar problems exist with "
1131  "vectors and tensors. Hence, to avoid this ambiguity, such "
1132  "assignments are not permitted.");
1133 
1139  "You are attempting to use functionality that is only available "
1140  "if deal.II was configured to use LAPACK, but cmake did not "
1141  "find a valid LAPACK library.");
1142 
1147  ExcNeedsHDF5,
1148  "You are attempting to use functionality that requires that deal.II is configured "
1149  "with HDF5 support. However, when you called 'cmake', HDF5 support "
1150  "was not detected.");
1151 
1156  ExcNeedsMPI,
1157  "You are attempting to use functionality that is only available "
1158  "if deal.II was configured to use MPI.");
1159 
1165  "You are attempting to use functionality that is only available "
1166  "if deal.II was configured to use the function parser which "
1167  "relies on the muparser library, but cmake did not "
1168  "find a valid muparser library on your system and also did "
1169  "not choose the one that comes bundled with deal.II.");
1170 
1176  "You are attempting to use functionality that is only available "
1177  "if deal.II was configured to use Assimp, but cmake did not "
1178  "find a valid Assimp library.");
1179 
1180 #ifdef DEAL_II_WITH_CUDA
1187  DeclException1(ExcCudaError, const char *, << arg1);
1192  std::string,
1193  << "There was an error in a cuSPARSE function: " << arg1);
1194 #endif
1202  "You are attempting to use functionality that is only available if deal.II "
1203  "was configured to use Trilinos' SEACAS library (which provides ExodusII), "
1204  "but cmake did not find a valid SEACAS library.");
1205 
1210  ExcNeedsCGAL,
1211  "You are attempting to use functionality that is only available "
1212  "if deal.II was configured to use CGAL, but cmake did not "
1213  "find a valid CGAL library.");
1214 
1215 #ifdef DEAL_II_WITH_MPI
1237  class ExcMPI : public ::ExceptionBase
1238  {
1239  public:
1240  ExcMPI(const int error_code);
1241 
1242  virtual void
1243  print_info(std::ostream &out) const override;
1244 
1245  const int error_code;
1246  };
1247 #endif // DEAL_II_WITH_MPI
1248 
1249 
1250 
1251 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
1260  class ExcExodusII : public ExceptionBase
1261  {
1262  public:
1268  ExcExodusII(const int error_code);
1269 
1273  virtual void
1274  print_info(std::ostream &out) const override;
1275 
1279  const int error_code;
1280  };
1281 #endif // DEAL_II_TRILINOS_WITH_SEACAS
1282 
1289  "A user call-back function encountered a recoverable error, "
1290  "but the underlying library that called the call-back did not "
1291  "manage to recover from the error and aborted its operation."
1292  "\n\n"
1293  "See the glossary entry on user call-back functions for more "
1294  "information.");
1295 } /*namespace StandardExceptions*/
1296 
1297 
1298 
1306 {
1307  namespace internals
1308  {
1316  extern bool allow_abort_on_exception;
1317  } // namespace internals
1318 
1337  void
1338  set_additional_assert_output(const char *const p);
1339 
1350  void
1352 
1367  void
1369 
1378  void
1380 
1388  namespace internals
1389  {
1394  [[noreturn]] void
1395  abort(const ExceptionBase &exc) noexcept;
1396 
1401  {
1412  };
1413 
1431  template <typename ExceptionType>
1432  [[noreturn]] void
1434  const char *file,
1435  int line,
1436  const char *function,
1437  const char *cond,
1438  const char *exc_name,
1439  ExceptionType e)
1440  {
1441  static_assert(std::is_base_of_v<ExceptionBase, ExceptionType>,
1442  "The provided exception must inherit from ExceptionBase.");
1443  // Fill the fields of the exception object
1444  e.set_fields(file, line, function, cond, exc_name);
1445 
1446  switch (handling)
1447  {
1449  {
1453  else
1454  {
1455  // We are not allowed to abort, so just throw the error:
1456  throw e;
1457  }
1458  }
1460  throw e;
1461  // this function should never return (and AssertNothrow can);
1462  // something must have gone wrong in the error handling code for us
1463  // to get this far, so throw an exception.
1464  default:
1466  }
1467  }
1468 
1472  void
1473  do_issue_error_nothrow(const ExceptionBase &e) noexcept;
1474 
1483  template <typename ExceptionType>
1484  void
1485  issue_error_nothrow(const char *file,
1486  int line,
1487  const char *function,
1488  const char *cond,
1489  const char *exc_name,
1490  ExceptionType e) noexcept
1491  {
1492  static_assert(std::is_base_of_v<ExceptionBase, ExceptionType>,
1493  "The provided exception must inherit from ExceptionBase.");
1494  // Fill the fields of the exception object
1495  e.set_fields(file, line, function, cond, exc_name);
1496  // avoid moving a bunch of code into the header by dispatching to
1497  // another function:
1499  }
1500 #ifdef DEAL_II_WITH_CUDA
1506  std::string
1507  get_cusparse_error_string(const cusparseStatus_t error_code);
1508 
1514  std::string
1515  get_cusolver_error_string(const cusolverStatus_t error_code);
1516 #endif
1517  } /*namespace internals*/
1518 
1519 } /*namespace deal_II_exceptions*/
1520 
1521 
1522 
1548 #ifdef DEBUG
1549 # if KOKKOS_VERSION >= 30600
1550 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1551 # define Assert(cond, exc) \
1552  do \
1553  { \
1554  KOKKOS_IF_ON_HOST(({ \
1555  if (__builtin_expect(!(cond), false)) \
1556  ::deal_II_exceptions::internals::issue_error_noreturn( \
1557  ::deal_II_exceptions::internals::ExceptionHandling:: \
1558  abort_or_throw_on_exception, \
1559  __FILE__, \
1560  __LINE__, \
1561  __PRETTY_FUNCTION__, \
1562  #cond, \
1563  #exc, \
1564  exc); \
1565  })) \
1566  KOKKOS_IF_ON_DEVICE(({ \
1567  if (!(cond)) \
1568  Kokkos::abort(#cond); \
1569  })) \
1570  } \
1571  while (false)
1572 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1573 # define Assert(cond, exc) \
1574  do \
1575  { \
1576  KOKKOS_IF_ON_HOST(({ \
1577  if (!(cond)) \
1578  ::deal_II_exceptions::internals::issue_error_noreturn( \
1579  ::deal_II_exceptions::internals::ExceptionHandling:: \
1580  abort_or_throw_on_exception, \
1581  __FILE__, \
1582  __LINE__, \
1583  __PRETTY_FUNCTION__, \
1584  #cond, \
1585  #exc, \
1586  exc); \
1587  })) \
1588  KOKKOS_IF_ON_DEVICE(({ \
1589  if (!(cond)) \
1590  Kokkos::abort(#cond); \
1591  })) \
1592  } \
1593  while (false)
1594 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1595 # else /*if KOKKOS_VERSION >= 30600*/
1596 # ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1597 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1598 # define Assert(cond, exc) \
1599  do \
1600  { \
1601  if (__builtin_expect(!(cond), false)) \
1602  ::deal_II_exceptions::internals::issue_error_noreturn( \
1603  ::deal_II_exceptions::internals::ExceptionHandling:: \
1604  abort_or_throw_on_exception, \
1605  __FILE__, \
1606  __LINE__, \
1607  __PRETTY_FUNCTION__, \
1608  #cond, \
1609  #exc, \
1610  exc); \
1611  } \
1612  while (false)
1613 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1614 # define Assert(cond, exc) \
1615  do \
1616  { \
1617  if (!(cond)) \
1618  ::deal_II_exceptions::internals::issue_error_noreturn( \
1619  ::deal_II_exceptions::internals::ExceptionHandling:: \
1620  abort_or_throw_on_exception, \
1621  __FILE__, \
1622  __LINE__, \
1623  __PRETTY_FUNCTION__, \
1624  #cond, \
1625  #exc, \
1626  exc); \
1627  } \
1628  while (false)
1629 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1630 # else /*#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1631 # define Assert(cond, exc) \
1632  do \
1633  { \
1634  if (!(cond)) \
1635  Kokkos::abort(#cond); \
1636  } \
1637  while (false)
1638 # endif /*ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1639 # endif /*KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1640 #else /*ifdef DEBUG*/
1641 # define Assert(cond, exc) \
1642  do \
1643  { \
1644  } \
1645  while (false)
1646 #endif /*ifdef DEBUG*/
1647 
1648 
1649 
1676 #ifdef DEBUG
1677 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1678 # define AssertNothrow(cond, exc) \
1679  do \
1680  { \
1681  if (__builtin_expect(!(cond), false)) \
1682  ::deal_II_exceptions::internals::issue_error_nothrow( \
1683  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1684  } \
1685  while (false)
1686 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1687 # define AssertNothrow(cond, exc) \
1688  do \
1689  { \
1690  if (!(cond)) \
1691  ::deal_II_exceptions::internals::issue_error_nothrow( \
1692  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1693  } \
1694  while (false)
1695 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1696 #else
1697 # define AssertNothrow(cond, exc) \
1698  do \
1699  { \
1700  } \
1701  while (false)
1702 #endif
1703 
1731 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1732 # define AssertThrow(cond, exc) \
1733  do \
1734  { \
1735  if (__builtin_expect(!(cond), false)) \
1736  ::deal_II_exceptions::internals::issue_error_noreturn( \
1737  ::deal_II_exceptions::internals::ExceptionHandling:: \
1738  throw_on_exception, \
1739  __FILE__, \
1740  __LINE__, \
1741  __PRETTY_FUNCTION__, \
1742  #cond, \
1743  #exc, \
1744  exc); \
1745  } \
1746  while (false)
1747 #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1748 # define AssertThrow(cond, exc) \
1749  do \
1750  { \
1751  if (!(cond)) \
1752  ::deal_II_exceptions::internals::issue_error_noreturn( \
1753  ::deal_II_exceptions::internals::ExceptionHandling:: \
1754  throw_on_exception, \
1755  __FILE__, \
1756  __LINE__, \
1757  __PRETTY_FUNCTION__, \
1758  #cond, \
1759  #exc, \
1760  exc); \
1761  } \
1762  while (false)
1763 #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1764 
1765 
1766 namespace deal_II_exceptions
1767 {
1768  namespace internals
1769  {
1775  template <typename T, typename U>
1776  inline DEAL_II_HOST_DEVICE constexpr bool
1777  compare_for_equality(const T &t, const U &u)
1778  {
1779  using common_type = std::common_type_t<T, U>;
1780  return static_cast<common_type>(t) == static_cast<common_type>(u);
1781  }
1782 
1783 
1789  template <typename T, typename U>
1790  inline DEAL_II_HOST_DEVICE constexpr bool
1791  compare_less_than(const T &t, const U &u)
1792  {
1793  using common_type = std::common_type_t<T, U>;
1794  return (static_cast<common_type>(t) < static_cast<common_type>(u));
1795  }
1796  } // namespace internals
1797 } // namespace deal_II_exceptions
1798 
1799 
1820 #define AssertDimension(dim1, dim2) \
1821  Assert(::deal_II_exceptions::internals::compare_for_equality(dim1, \
1822  dim2), \
1823  ::ExcDimensionMismatch((dim1), (dim2)))
1824 
1825 
1843 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \
1844  AssertDimension(VEC.size(), DIM1); \
1845  for (const auto &subvector : VEC) \
1846  { \
1847  (void)subvector; \
1848  AssertDimension(subvector.size(), DIM2); \
1849  }
1850 
1851 namespace internal
1852 {
1853  // Workaround to allow for commas in template parameter lists
1854  // in preprocessor macros as found in
1855  // https://stackoverflow.com/questions/13842468/comma-in-c-c-macro
1856  template <typename F>
1858 
1859  template <typename T, typename U>
1860  struct argument_type<T(U)>
1861  {
1862  using type = U;
1863  };
1864 
1865  template <typename F>
1867 } // namespace internal
1868 
1888 #define AssertIndexRange(index, range) \
1889  Assert(::deal_II_exceptions::internals::compare_less_than(index, \
1890  range), \
1891  ExcIndexRangeType<::internal::argument_type_t<void( \
1892  std::common_type_t<decltype(index), decltype(range)>)>>((index), \
1893  0, \
1894  (range)))
1895 
1915 #define AssertIsFinite(number) \
1916  Assert(::numbers::is_finite(number), \
1917  ::ExcNumberNotFinite(std::complex<double>(number)))
1918 
1924 #define AssertIsNotUsed(obj) Assert((obj)->used() == false, ExcInternalError())
1925 
1926 #ifdef DEAL_II_WITH_MPI
1947 # define AssertThrowMPI(error_code) \
1948  AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code))
1949 #else
1950 # define AssertThrowMPI(error_code) \
1951  do \
1952  { \
1953  } \
1954  while (false)
1955 #endif // DEAL_II_WITH_MPI
1956 
1957 #ifdef DEAL_II_WITH_CUDA
1975 # ifdef DEBUG
1976 # define AssertCuda(error_code) \
1977  Assert(error_code == cudaSuccess, \
1978  ::ExcCudaError(cudaGetErrorString(error_code)))
1979 # else
1980 # define AssertCuda(error_code) \
1981  do \
1982  { \
1983  (void)(error_code); \
1984  } \
1985  while (false)
1986 # endif
1987 
2004 # ifdef DEBUG
2005 # define AssertNothrowCuda(error_code) \
2006  AssertNothrow(error_code == cudaSuccess, \
2007  ::ExcCudaError(cudaGetErrorString(error_code)))
2008 # else
2009 # define AssertNothrowCuda(error_code) \
2010  do \
2011  { \
2012  (void)(error_code); \
2013  } \
2014  while (false)
2015 # endif
2016 
2034 # ifdef DEBUG
2035 # define AssertCudaKernel() \
2036  do \
2037  { \
2038  cudaError_t local_error_code = cudaPeekAtLastError(); \
2039  AssertCuda(local_error_code); \
2040  local_error_code = cudaDeviceSynchronize(); \
2041  AssertCuda(local_error_code); \
2042  } \
2043  while (false)
2044 # else
2045 # define AssertCudaKernel() \
2046  do \
2047  { \
2048  } \
2049  while (false)
2050 # endif
2051 
2069 # ifdef DEBUG
2070 # define AssertCusparse(error_code) \
2071  Assert( \
2072  error_code == CUSPARSE_STATUS_SUCCESS, \
2073  ExcCusparseError( \
2074  deal_II_exceptions::internals::get_cusparse_error_string( \
2075  error_code)))
2076 # else
2077 # define AssertCusparse(error_code) \
2078  do \
2079  { \
2080  (void)(error_code); \
2081  } \
2082  while (false)
2083 # endif
2084 
2101 # ifdef DEBUG
2102 # define AssertNothrowCusparse(error_code) \
2103  AssertNothrow( \
2104  error_code == CUSPARSE_STATUS_SUCCESS, \
2105  ExcCusparseError( \
2106  deal_II_exceptions::internals::get_cusparse_error_string( \
2107  error_code)))
2108 # else
2109 # define AssertNothrowCusparse(error_code) \
2110  do \
2111  { \
2112  (void)(error_code); \
2113  } \
2114  while (false)
2115 # endif
2116 
2134 # ifdef DEBUG
2135 # define AssertCusolver(error_code) \
2136  Assert( \
2137  error_code == CUSOLVER_STATUS_SUCCESS, \
2138  ExcCusparseError( \
2139  deal_II_exceptions::internals::get_cusolver_error_string( \
2140  error_code)))
2141 # else
2142 # define AssertCusolver(error_code) \
2143  do \
2144  { \
2145  (void)(error_code); \
2146  } \
2147  while (false)
2148 # endif
2149 
2150 #endif
2151 
2152 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
2170 # define AssertThrowExodusII(error_code) \
2171  AssertThrow(error_code == 0, \
2172  ::StandardExceptions::ExcExodusII(error_code));
2173 #endif // DEAL_II_TRILINOS_WITH_SEACAS
2174 
2175 using namespace StandardExceptions;
2176 
2178 
2179 #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:130
std::string what_str
Definition: exceptions.h:176
const char * get_exc_name() const
Definition: exceptions.cc:173
virtual ~ExceptionBase() noexcept override=default
int n_stacktrace_frames
Definition: exceptions.h:156
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:150
const char * function
Definition: exceptions.h:140
void print_exc_data(std::ostream &out) const
Definition: exceptions.cc:181
unsigned int line
Definition: exceptions.h:135
void * raw_stacktrace[25]
Definition: exceptions.h:162
const char * cond
Definition: exceptions.h:145
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:477
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition: config.h:491
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition: config.h:534
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
#define DeclException0(Exception0)
Definition: exceptions.h:472
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 & RecoverableUserCallbackError()
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 & ExcFunctionNonzeroReturn(std::string arg1, int 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:540
static ::ExceptionBase & ExcEmptyObject()
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:495
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
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:563
static ::ExceptionBase & ExcCusparseError(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:517
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:1791
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:1777
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:1433
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:1485
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
typename argument_type< F >::type argument_type_t
Definition: exceptions.h:1866
#define DEAL_II_HOST_DEVICE
Definition: numbers.h:35