Reference documentation for deal.II version GIT 0980a66d4b 2023-03-23 20:20:03+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 <Kokkos_Core.hpp>
22 
23 #include <exception>
24 #include <ostream>
25 #include <string>
26 #include <type_traits>
27 
28 #ifdef DEAL_II_WITH_CUDA
29 # include <cusolverSp.h>
30 # include <cusparse.h>
31 #endif
32 
34 
35 
49 class ExceptionBase : public std::exception
50 {
51 public:
55  ExceptionBase();
56 
61 
65  virtual ~ExceptionBase() noexcept override = default;
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 
150 
151 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
155  void *raw_stacktrace[25];
156 #endif
157 
158 private:
162  void
163  generate_message() const;
164 
169  mutable std::string what_str;
170 };
171 
172 #ifndef DOXYGEN
173 
190 # define DeclException0(Exception0) \
191  class Exception0 : public ::ExceptionBase \
192  {}
193 
194 
214 # define DeclExceptionMsg(Exception, defaulttext) \
215  class Exception : public ::ExceptionBase \
216  { \
217  public: \
218  Exception(const std::string &msg = defaulttext) \
219  : arg(msg) \
220  {} \
221  virtual ~Exception() noexcept \
222  {} \
223  virtual void \
224  print_info(std::ostream &out) const override \
225  { \
226  out << " " << arg << std::endl; \
227  } \
228  \
229  private: \
230  const std::string arg; \
231  }
232 
250 # define DeclException1(Exception1, type1, outsequence) \
251  class Exception1 : public ::ExceptionBase \
252  { \
253  public: \
254  Exception1(type1 const &a1) \
255  : arg1(a1) \
256  {} \
257  virtual ~Exception1() noexcept \
258  {} \
259  virtual void \
260  print_info(std::ostream &out) const override \
261  { \
262  out << " " outsequence << std::endl; \
263  } \
264  \
265  private: \
266  type1 const arg1; \
267  }
268 
269 
287 # define DeclException2(Exception2, type1, type2, outsequence) \
288  class Exception2 : public ::ExceptionBase \
289  { \
290  public: \
291  Exception2(type1 const &a1, type2 const &a2) \
292  : arg1(a1) \
293  , arg2(a2) \
294  {} \
295  virtual ~Exception2() noexcept \
296  {} \
297  virtual void \
298  print_info(std::ostream &out) const override \
299  { \
300  out << " " outsequence << std::endl; \
301  } \
302  \
303  private: \
304  type1 const arg1; \
305  type2 const arg2; \
306  }
307 
308 
326 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
327  class Exception3 : public ::ExceptionBase \
328  { \
329  public: \
330  Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \
331  : arg1(a1) \
332  , arg2(a2) \
333  , arg3(a3) \
334  {} \
335  virtual ~Exception3() noexcept \
336  {} \
337  virtual void \
338  print_info(std::ostream &out) const override \
339  { \
340  out << " " outsequence << std::endl; \
341  } \
342  \
343  private: \
344  type1 const arg1; \
345  type2 const arg2; \
346  type3 const arg3; \
347  }
348 
349 
367 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
368  class Exception4 : public ::ExceptionBase \
369  { \
370  public: \
371  Exception4(type1 const &a1, \
372  type2 const &a2, \
373  type3 const &a3, \
374  type4 const &a4) \
375  : arg1(a1) \
376  , arg2(a2) \
377  , arg3(a3) \
378  , arg4(a4) \
379  {} \
380  virtual ~Exception4() noexcept \
381  {} \
382  virtual void \
383  print_info(std::ostream &out) const override \
384  { \
385  out << " " outsequence << std::endl; \
386  } \
387  \
388  private: \
389  type1 const arg1; \
390  type2 const arg2; \
391  type3 const arg3; \
392  type4 const arg4; \
393  }
394 
395 
413 # define DeclException5( \
414  Exception5, type1, type2, type3, type4, type5, outsequence) \
415  class Exception5 : public ::ExceptionBase \
416  { \
417  public: \
418  Exception5(type1 const &a1, \
419  type2 const &a2, \
420  type3 const &a3, \
421  type4 const &a4, \
422  type5 const &a5) \
423  : arg1(a1) \
424  , arg2(a2) \
425  , arg3(a3) \
426  , arg4(a4) \
427  , arg5(a5) \
428  {} \
429  virtual ~Exception5() noexcept \
430  {} \
431  virtual void \
432  print_info(std::ostream &out) const override \
433  { \
434  out << " " outsequence << std::endl; \
435  } \
436  \
437  private: \
438  type1 const arg1; \
439  type2 const arg2; \
440  type3 const arg3; \
441  type4 const arg4; \
442  type5 const arg5; \
443  }
444 
445 #else /*ifndef DOXYGEN*/
446 
447 // Dummy definitions for doxygen:
448 
465 # define DeclException0(Exception0) \
466  \
467  static ::ExceptionBase &Exception0()
468 
488 # define DeclExceptionMsg(Exception, defaulttext) \
489  \
490  \
491  static ::ExceptionBase &Exception()
492 
510 # define DeclException1(Exception1, type1, outsequence) \
511  \
512  \
513  static ::ExceptionBase &Exception1(type1 arg1)
514 
515 
533 # define DeclException2(Exception2, type1, type2, outsequence) \
534  \
535  \
536  static ::ExceptionBase &Exception2(type1 arg1, type2 arg2)
537 
538 
556 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
557  \
558  \
559  static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3)
560 
561 
579 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
580  \
581  \
582  static ::ExceptionBase &Exception4(type1 arg1, \
583  type2 arg2, \
584  type3 arg3, \
585  type4 arg4)
586 
587 
605 # define DeclException5( \
606  Exception5, type1, type2, type3, type4, type5, outsequence) \
607  \
608  \
609  static ::ExceptionBase &Exception5( \
610  type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)
611 
612 #endif /*ifndef DOXYGEN*/
613 
614 
627 {
637  "A piece of code is attempting a division by zero. This is "
638  "likely going to lead to results that make no sense.");
639 
652  std::complex<double>,
653  << "In a significant number of places, deal.II checks that some intermediate "
654  << "value is a finite number (as opposed to plus or minus infinity, or "
655  << "NaN/Not a Number). In the current function, we encountered a number "
656  << "that is not finite (its value is " << arg1 << " and therefore "
657  << "violates the current assertion).\n\n"
658  << "This may be due to the fact that some operation in this function "
659  << "created such a value, or because one of the arguments you passed "
660  << "to the function already had this value from some previous "
661  << "operation. In the latter case, this function only triggered the "
662  << "error but may not actually be responsible for the computation of "
663  << "the number that is not finite.\n\n"
664  << "There are two common cases where this situation happens. First, your "
665  << "code (or something in deal.II) divides by zero in a place where this "
666  << "should not happen. Or, you are trying to solve a linear system "
667  << "with an unsuitable solver (such as an indefinite or non-symmetric "
668  << "linear system using a Conjugate Gradient solver); such attempts "
669  << "oftentimes yield an operation somewhere that tries to divide "
670  << "by zero or take the square root of a negative value.\n\n"
671  << "In any case, when trying to find the source of the error, "
672  << "recall that the location where you are getting this error is "
673  << "simply the first place in the program where there is a check "
674  << "that a number (e.g., an element of a solution vector) is in fact "
675  << "finite, but that the actual error that computed the number "
676  << "may have happened far earlier. To find this location, you "
677  << "may want to add checks for finiteness in places of your "
678  << "program visited before the place where this error is produced. "
679  << "One way to check for finiteness is to use the 'AssertIsFinite' "
680  << "macro.");
681 
686  std::size_t,
687  "Your program tried to allocate some memory but this "
688  "allocation failed. Typically, this either means that "
689  "you simply do not have enough memory in your system, "
690  "or that you are (erroneously) trying to allocate "
691  "a chunk of memory that is simply beyond all reasonable "
692  "size, for example because the size of the object has "
693  "been computed incorrectly."
694  "\n\n"
695  "In the current case, the request was for "
696  << arg1 << " bytes.");
697 
703  int,
704  << "Destroying memory handler while " << arg1
705  << " objects are still allocated.");
706 
711  "An input/output error has occurred. There are a number of "
712  "reasons why this may be happening, both for reading and "
713  "writing operations."
714  "\n\n"
715  "If this happens during an operation that tries to read "
716  "data: First, you may be "
717  "trying to read from a file that doesn't exist or that is "
718  "not readable given its file permissions. Second, deal.II "
719  "uses this error at times if it tries to "
720  "read information from a file but where the information "
721  "in the file does not correspond to the expected format. "
722  "An example would be a truncated file, or a mesh file "
723  "that contains not only sections that describe the "
724  "vertices and cells, but also sections for additional "
725  "data that deal.II does not understand."
726  "\n\n"
727  "If this happens during an operation that tries to write "
728  "data: you may be trying to write to a file to which file "
729  "or directory permissions do not allow you to write. A "
730  "typical example is where you specify an output file in "
731  "a directory that does not exist.");
732 
740  std::string,
741  << "Could not open file " << arg1
742  << "."
743  "\n\n"
744  "If this happens during an operation that tries to read "
745  "data: you may be "
746  "trying to read from a file that doesn't exist or that is "
747  "not readable given its file permissions."
748  "\n\n"
749  "If this happens during an operation that tries to write "
750  "data: you may be trying to write to a file to which file "
751  "or directory permissions do not allow you to write. A "
752  "typical example is where you specify an output file in "
753  "a directory that does not exist.");
754 
764  "You are trying to use functionality in deal.II that is "
765  "currently not implemented. In many cases, this indicates "
766  "that there simply didn't appear much of a need for it, or "
767  "that the author of the original code did not have the "
768  "time to implement a particular case. If you hit this "
769  "exception, it is therefore worth the time to look into "
770  "the code to find out whether you may be able to "
771  "implement the missing functionality. If you do, please "
772  "consider providing a patch to the deal.II development "
773  "sources (see the deal.II website on how to contribute).");
774 
796  "This exception -- which is used in many places in the "
797  "library -- usually indicates that some condition which "
798  "the author of the code thought must be satisfied at a "
799  "certain point in an algorithm, is not fulfilled. An "
800  "example would be that the first part of an algorithm "
801  "sorts elements of an array in ascending order, and "
802  "a second part of the algorithm later encounters an "
803  "element that is not larger than the previous one."
804  "\n\n"
805  "There is usually not very much you can do if you "
806  "encounter such an exception since it indicates an error "
807  "in deal.II, not in your own program. Try to come up with "
808  "the smallest possible program that still demonstrates "
809  "the error and contact the deal.II mailing lists with it "
810  "to obtain help.");
811 
820  "You (or a place in the library) are trying to call a "
821  "function that is declared as a virtual function in a "
822  "base class but that has not been overridden in your "
823  "derived class."
824  "\n\n"
825  "This exception happens in cases where the base class "
826  "cannot provide a useful default implementation for "
827  "the virtual function, but where we also do not want "
828  "to mark the function as abstract (i.e., with '=0' at the end) "
829  "because the function is not essential to the class in many "
830  "contexts. In cases like this, the base class provides "
831  "a dummy implementation that makes the compiler happy, but "
832  "that then throws the current exception."
833  "\n\n"
834  "A concrete example would be the 'Function' class. It declares "
835  "the existence of 'value()' and 'gradient()' member functions, "
836  "and both are marked as 'virtual'. Derived classes have to "
837  "override these functions for the values and gradients of a "
838  "particular function. On the other hand, not every function "
839  "has a gradient, and even for those that do, not every program "
840  "actually needs to evaluate it. Consequently, there is no "
841  "*requirement* that a derived class actually override the "
842  "'gradient()' function (as there would be had it been marked "
843  "as abstract). But, since the base class cannot know how to "
844  "compute the gradient, if a derived class does not override "
845  "the 'gradient()' function and it is called anyway, then the "
846  "default implementation in the base class will simply throw "
847  "an exception."
848  "\n\n"
849  "The exception you see is what happens in cases such as the "
850  "one just illustrated. To fix the problem, you need to "
851  "investigate whether the function being called should indeed have "
852  "been called; if the answer is 'yes', then you need to "
853  "implement the missing override in your class.");
854 
859  std::string,
860  << "Please provide an implementation for the function \""
861  << arg1 << "\"");
862 
867 
872 
880  int,
881  << "You are trying to execute functionality that is "
882  << "impossible in " << arg1
883  << "d or simply does not make any sense.");
884 
893  int,
894  int,
895  << "You are trying to execute functionality that is "
896  << "impossible in dimensions <" << arg1 << ',' << arg2
897  << "> or simply does not make any sense.");
898 
899 
904  "In a check in the code, deal.II encountered a zero in "
905  "a place where this does not make sense. See the condition "
906  "that was being checked and that is printed further up "
907  "in the error message to get more information on what "
908  "the erroneous zero corresponds to.");
909 
915  "The object you are trying to access is empty but it makes "
916  "no sense to attempt the operation you are trying on an "
917  "empty object.");
918 
927  std::size_t,
928  std::size_t,
929  << "Two sizes or dimensions were supposed to be equal, "
930  << "but aren't. They are " << arg1 << " and " << arg2 << '.');
931 
937  std::size_t,
938  std::size_t,
939  std::size_t,
940  << "The size or dimension of one object, " << arg1
941  << " was supposed to be "
942  << "equal to one of two values, but isn't. The two possible "
943  << "values are " << arg2 << " and " << arg3 << '.');
944 
959  std::size_t,
960  std::size_t,
961  std::size_t,
962  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
963  << arg3 << ")."
964  << (arg2 == arg3 ?
965  " In the current case, this half-open range is in fact empty, "
966  "suggesting that you are accessing an element of an empty "
967  "collection such as a vector that has not been set to the "
968  "correct size." :
969  ""));
970 
986  template <typename T>
989  T,
990  T,
991  T,
992  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
993  << arg3 << ")."
994  << (arg2 == arg3 ?
995  " In the current case, this half-open range is in fact empty, "
996  "suggesting that you are accessing an element of an empty "
997  "collection such as a vector that has not been set to the "
998  "correct size." :
999  ""));
1000 
1005  int,
1006  int,
1007  << "Number " << arg1 << " must be larger than or equal "
1008  << arg2 << '.');
1009 
1013  template <typename T>
1015  T,
1016  T,
1017  << "Number " << arg1 << " must be larger than or equal "
1018  << arg2 << '.');
1019 
1025  int,
1026  int,
1027  << "Division " << arg1 << " by " << arg2
1028  << " has remainder different from zero.");
1029 
1039  "You are trying to use an iterator, but the iterator is "
1040  "in an invalid state. This may indicate that the iterator "
1041  "object has not been initialized, or that it has been "
1042  "moved beyond the end of the range of valid elements.");
1043 
1049  "You are trying to use an iterator, but the iterator is "
1050  "pointing past the end of the range of valid elements. "
1051  "It is not valid to dereference the iterator in this "
1052  "case.");
1053 
1067  DeclException1(ExcMessage, std::string, << arg1);
1068 
1073  "You are trying an operation on a vector that is only "
1074  "allowed if the vector has no ghost elements, but the "
1075  "vector you are operating on does have ghost elements. "
1076  "Specifically, vectors with ghost elements are read-only "
1077  "and cannot appear in operations that write into these "
1078  "vectors."
1079  "\n\n"
1080  "See the glossary entry on 'Ghosted vectors' for more "
1081  "information.");
1082 
1088  int,
1089  << "Something went wrong when making cell " << arg1
1090  << ". Read the docs and the source code "
1091  << "for more information.");
1092 
1101  "You are trying an operation of the form 'vector = C', "
1102  "'matrix = C', or 'tensor = C' with a nonzero scalar value "
1103  "'C'. However, such assignments are only allowed if the "
1104  "C is zero, since the semantics for assigning any other "
1105  "value are not clear. For example: one could interpret "
1106  "assigning a matrix a value of 1 to mean the matrix has a "
1107  "norm of 1, the matrix is the identity matrix, or the "
1108  "matrix contains only 1s. Similar problems exist with "
1109  "vectors and tensors. Hence, to avoid this ambiguity, such "
1110  "assignments are not permitted.");
1111 
1117  "You are attempting to use functionality that is only available "
1118  "if deal.II was configured to use LAPACK, but cmake did not "
1119  "find a valid LAPACK library.");
1120 
1125  ExcNeedsHDF5,
1126  "You are attempting to use functionality that requires that deal.II is configured "
1127  "with HDF5 support. However, when you called 'cmake', HDF5 support "
1128  "was not detected.");
1129 
1134  ExcNeedsMPI,
1135  "You are attempting to use functionality that is only available "
1136  "if deal.II was configured to use MPI.");
1137 
1143  "You are attempting to use functionality that is only available "
1144  "if deal.II was configured to use the function parser which "
1145  "relies on the muparser library, but cmake did not "
1146  "find a valid muparser library on your system and also did "
1147  "not choose the one that comes bundled with deal.II.");
1148 
1154  "You are attempting to use functionality that is only available "
1155  "if deal.II was configured to use Assimp, but cmake did not "
1156  "find a valid Assimp library.");
1157 
1158 #ifdef DEAL_II_WITH_CUDA
1165  DeclException1(ExcCudaError, const char *, << arg1);
1170  std::string,
1171  << "There was an error in a cuSPARSE function: " << arg1);
1172 #endif
1180  "You are attempting to use functionality that is only available if deal.II "
1181  "was configured to use Trilinos' SEACAS library (which provides ExodusII), "
1182  "but cmake did not find a valid SEACAS library.");
1183 
1188  ExcNeedsCGAL,
1189  "You are attempting to use functionality that is only available "
1190  "if deal.II was configured to use CGAL, but cmake did not "
1191  "find a valid CGAL library.");
1192 
1193 #ifdef DEAL_II_WITH_MPI
1215  class ExcMPI : public ::ExceptionBase
1216  {
1217  public:
1218  ExcMPI(const int error_code);
1219 
1220  virtual void
1221  print_info(std::ostream &out) const override;
1222 
1223  const int error_code;
1224  };
1225 #endif // DEAL_II_WITH_MPI
1226 
1227 
1228 
1229 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
1238  class ExcExodusII : public ExceptionBase
1239  {
1240  public:
1246  ExcExodusII(const int error_code);
1247 
1251  virtual void
1252  print_info(std::ostream &out) const override;
1253 
1257  const int error_code;
1258  };
1259 #endif // DEAL_II_TRILINOS_WITH_SEACAS
1260 } /*namespace StandardExceptions*/
1261 
1262 
1263 
1271 {
1272  namespace internals
1273  {
1281  extern bool allow_abort_on_exception;
1282  } // namespace internals
1283 
1302  void
1303  set_additional_assert_output(const char *const p);
1304 
1315  void
1317 
1332  void
1334 
1343  void
1345 
1353  namespace internals
1354  {
1359  [[noreturn]] void
1360  abort(const ExceptionBase &exc) noexcept;
1361 
1366  {
1377  };
1378 
1396  template <class ExceptionType>
1397  [[noreturn]] void
1399  const char * file,
1400  int line,
1401  const char * function,
1402  const char * cond,
1403  const char * exc_name,
1404  ExceptionType e)
1405  {
1406  // Fill the fields of the exception object
1407  e.set_fields(file, line, function, cond, exc_name);
1408 
1409  switch (handling)
1410  {
1412  {
1416  else
1417  {
1418  // We are not allowed to abort, so just throw the error:
1419  throw e;
1420  }
1421  }
1423  throw e;
1424  // this function should never return (and AssertNothrow can);
1425  // something must have gone wrong in the error handling code for us
1426  // to get this far, so throw an exception.
1427  default:
1429  }
1430  }
1431 
1435  void
1436  do_issue_error_nothrow(const ExceptionBase &e) noexcept;
1437 
1446  template <class ExceptionType>
1447  void
1448  issue_error_nothrow(const char * file,
1449  int line,
1450  const char * function,
1451  const char * cond,
1452  const char * exc_name,
1453  ExceptionType e) noexcept
1454  {
1455  static_assert(std::is_base_of<ExceptionBase, ExceptionType>::value,
1456  "The provided exception must inherit from ExceptionBase.");
1457  // Fill the fields of the exception object
1458  e.set_fields(file, line, function, cond, exc_name);
1459  // avoid moving a bunch of code into the header by dispatching to
1460  // another function:
1462  }
1463 #ifdef DEAL_II_WITH_CUDA
1469  std::string
1470  get_cusparse_error_string(const cusparseStatus_t error_code);
1471 
1477  std::string
1478  get_cusolver_error_string(const cusolverStatus_t error_code);
1479 #endif
1480  } /*namespace internals*/
1481 
1482 } /*namespace deal_II_exceptions*/
1483 
1484 
1485 
1511 #ifdef DEBUG
1512 # if KOKKOS_VERSION >= 30600
1513 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1514 # define Assert(cond, exc) \
1515  { \
1516  KOKKOS_IF_ON_HOST(({ \
1517  if (__builtin_expect(!(cond), false)) \
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  KOKKOS_IF_ON_DEVICE(({ \
1529  if (!(cond)) \
1530  Kokkos::abort(#cond); \
1531  })) \
1532  }
1533 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1534 # define Assert(cond, exc) \
1535  { \
1536  KOKKOS_IF_ON_HOST(({ \
1537  if (!(cond)) \
1538  ::deal_II_exceptions::internals::issue_error_noreturn( \
1539  ::deal_II_exceptions::internals::ExceptionHandling:: \
1540  abort_or_throw_on_exception, \
1541  __FILE__, \
1542  __LINE__, \
1543  __PRETTY_FUNCTION__, \
1544  #cond, \
1545  #exc, \
1546  exc); \
1547  })) \
1548  KOKKOS_IF_ON_DEVICE(({ \
1549  if (!(cond)) \
1550  Kokkos::abort(#cond); \
1551  })) \
1552  }
1553 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1554 # else /*if KOKKOS_VERSION >= 30600*/
1555 # ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1556 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1557 # define Assert(cond, exc) \
1558  { \
1559  if (__builtin_expect(!(cond), false)) \
1560  ::deal_II_exceptions::internals::issue_error_noreturn( \
1561  ::deal_II_exceptions::internals::ExceptionHandling:: \
1562  abort_or_throw_on_exception, \
1563  __FILE__, \
1564  __LINE__, \
1565  __PRETTY_FUNCTION__, \
1566  #cond, \
1567  #exc, \
1568  exc); \
1569  }
1570 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1571 # define Assert(cond, exc) \
1572  { \
1573  if (!(cond)) \
1574  ::deal_II_exceptions::internals::issue_error_noreturn( \
1575  ::deal_II_exceptions::internals::ExceptionHandling:: \
1576  abort_or_throw_on_exception, \
1577  __FILE__, \
1578  __LINE__, \
1579  __PRETTY_FUNCTION__, \
1580  #cond, \
1581  #exc, \
1582  exc); \
1583  }
1584 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1585 # else /*#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1586 # define Assert(cond, exc) \
1587  { \
1588  if (!(cond)) \
1589  Kokkos::abort(#cond); \
1590  }
1591 # endif /*ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1592 # endif /*KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1593 #else /*ifdef DEBUG*/
1594 # define Assert(cond, exc) \
1595  {}
1596 #endif /*ifdef DEBUG*/
1597 
1598 
1599 
1626 #ifdef DEBUG
1627 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1628 # define AssertNothrow(cond, exc) \
1629  { \
1630  if (__builtin_expect(!(cond), false)) \
1631  ::deal_II_exceptions::internals::issue_error_nothrow( \
1632  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1633  }
1634 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1635 # define AssertNothrow(cond, exc) \
1636  { \
1637  if (!(cond)) \
1638  ::deal_II_exceptions::internals::issue_error_nothrow( \
1639  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1640  }
1641 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1642 #else
1643 # define AssertNothrow(cond, exc) \
1644  {}
1645 #endif
1646 
1674 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1675 # define AssertThrow(cond, exc) \
1676  { \
1677  if (__builtin_expect(!(cond), false)) \
1678  ::deal_II_exceptions::internals::issue_error_noreturn( \
1679  ::deal_II_exceptions::internals::ExceptionHandling:: \
1680  throw_on_exception, \
1681  __FILE__, \
1682  __LINE__, \
1683  __PRETTY_FUNCTION__, \
1684  #cond, \
1685  #exc, \
1686  exc); \
1687  }
1688 #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1689 # define AssertThrow(cond, exc) \
1690  { \
1691  if (!(cond)) \
1692  ::deal_II_exceptions::internals::issue_error_noreturn( \
1693  ::deal_II_exceptions::internals::ExceptionHandling:: \
1694  throw_on_exception, \
1695  __FILE__, \
1696  __LINE__, \
1697  __PRETTY_FUNCTION__, \
1698  #cond, \
1699  #exc, \
1700  exc); \
1701  }
1702 #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1703 
1704 
1705 namespace deal_II_exceptions
1706 {
1707  namespace internals
1708  {
1714  template <typename T, typename U>
1715  inline DEAL_II_HOST_DEVICE constexpr bool
1716  compare_for_equality(const T &t, const U &u)
1717  {
1718  using common_type = std::common_type_t<T, U>;
1719  return static_cast<common_type>(t) == static_cast<common_type>(u);
1720  }
1721 
1722 
1728  template <typename T, typename U>
1729  inline DEAL_II_HOST_DEVICE constexpr bool
1730  compare_less_than(const T &t, const U &u)
1731  {
1732  using common_type = std::common_type_t<T, U>;
1733  return (static_cast<common_type>(t) < static_cast<common_type>(u));
1734  }
1735  } // namespace internals
1736 } // namespace deal_II_exceptions
1737 
1738 
1759 #define AssertDimension(dim1, dim2) \
1760  Assert(::deal_II_exceptions::internals::compare_for_equality(dim1, \
1761  dim2), \
1762  ::ExcDimensionMismatch((dim1), (dim2)))
1763 
1764 
1782 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \
1783  AssertDimension(VEC.size(), DIM1); \
1784  for (const auto &subvector : VEC) \
1785  { \
1786  (void)subvector; \
1787  AssertDimension(subvector.size(), DIM2); \
1788  }
1789 
1790 namespace internal
1791 {
1792  // Workaround to allow for commas in template parameter lists
1793  // in preprocessor macros as found in
1794  // https://stackoverflow.com/questions/13842468/comma-in-c-c-macro
1795  template <typename F>
1797 
1798  template <typename T, typename U>
1799  struct argument_type<T(U)>
1800  {
1801  using type = U;
1802  };
1803 
1804  template <typename F>
1806 } // namespace internal
1807 
1827 #define AssertIndexRange(index, range) \
1828  Assert(::deal_II_exceptions::internals::compare_less_than(index, \
1829  range), \
1830  ExcIndexRangeType<::internal::argument_type_t<void( \
1831  std::common_type_t<decltype(index), decltype(range)>)>>((index), \
1832  0, \
1833  (range)))
1834 
1854 #define AssertIsFinite(number) \
1855  Assert(::numbers::is_finite(number), \
1856  ::ExcNumberNotFinite(std::complex<double>(number)))
1857 
1863 #define AssertIsNotUsed(obj) Assert((obj)->used() == false, ExcInternalError())
1864 
1865 #ifdef DEAL_II_WITH_MPI
1886 # define AssertThrowMPI(error_code) \
1887  AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code))
1888 #else
1889 # define AssertThrowMPI(error_code) \
1890  {}
1891 #endif // DEAL_II_WITH_MPI
1892 
1893 #ifdef DEAL_II_WITH_CUDA
1911 # ifdef DEBUG
1912 # define AssertCuda(error_code) \
1913  Assert(error_code == cudaSuccess, \
1914  ::ExcCudaError(cudaGetErrorString(error_code)))
1915 # else
1916 # define AssertCuda(error_code) \
1917  { \
1918  (void)(error_code); \
1919  }
1920 # endif
1921 
1938 # ifdef DEBUG
1939 # define AssertNothrowCuda(error_code) \
1940  AssertNothrow(error_code == cudaSuccess, \
1941  ::ExcCudaError(cudaGetErrorString(error_code)))
1942 # else
1943 # define AssertNothrowCuda(error_code) \
1944  { \
1945  (void)(error_code); \
1946  }
1947 # endif
1948 
1966 # ifdef DEBUG
1967 # define AssertCudaKernel() \
1968  { \
1969  cudaError_t local_error_code = cudaPeekAtLastError(); \
1970  AssertCuda(local_error_code); \
1971  local_error_code = cudaDeviceSynchronize(); \
1972  AssertCuda(local_error_code) \
1973  }
1974 # else
1975 # define AssertCudaKernel() \
1976  {}
1977 # endif
1978 
1996 # ifdef DEBUG
1997 # define AssertCusparse(error_code) \
1998  Assert( \
1999  error_code == CUSPARSE_STATUS_SUCCESS, \
2000  ExcCusparseError( \
2001  deal_II_exceptions::internals::get_cusparse_error_string( \
2002  error_code)))
2003 # else
2004 # define AssertCusparse(error_code) \
2005  { \
2006  (void)(error_code); \
2007  }
2008 # endif
2009 
2026 # ifdef DEBUG
2027 # define AssertNothrowCusparse(error_code) \
2028  AssertNothrow( \
2029  error_code == CUSPARSE_STATUS_SUCCESS, \
2030  ExcCusparseError( \
2031  deal_II_exceptions::internals::get_cusparse_error_string( \
2032  error_code)))
2033 # else
2034 # define AssertNothrowCusparse(error_code) \
2035  { \
2036  (void)(error_code); \
2037  }
2038 # endif
2039 
2057 # ifdef DEBUG
2058 # define AssertCusolver(error_code) \
2059  Assert( \
2060  error_code == CUSOLVER_STATUS_SUCCESS, \
2061  ExcCusparseError( \
2062  deal_II_exceptions::internals::get_cusolver_error_string( \
2063  error_code)))
2064 # else
2065 # define AssertCusolver(error_code) \
2066  { \
2067  (void)(error_code); \
2068  }
2069 # endif
2070 
2071 #endif
2072 
2073 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
2091 # define AssertThrowExodusII(error_code) \
2092  AssertThrow(error_code == 0, \
2093  ::StandardExceptions::ExcExodusII(error_code));
2094 #endif // DEAL_II_TRILINOS_WITH_SEACAS
2095 
2096 using namespace StandardExceptions;
2097 
2099 
2100 #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:123
std::string what_str
Definition: exceptions.h:169
const char * get_exc_name() const
Definition: exceptions.cc:173
virtual ~ExceptionBase() noexcept override=default
int n_stacktrace_frames
Definition: exceptions.h:149
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:143
const char * function
Definition: exceptions.h:133
void print_exc_data(std::ostream &out) const
Definition: exceptions.cc:181
unsigned int line
Definition: exceptions.h:128
void * raw_stacktrace[25]
Definition: exceptions.h:155
const char * cond
Definition: exceptions.h:138
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:474
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:475
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
#define DeclException0(Exception0)
Definition: exceptions.h:465
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:533
static ::ExceptionBase & ExcEmptyObject()
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:488
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:556
static ::ExceptionBase & ExcCusparseError(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:510
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:1730
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:1716
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:1398
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:1448
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:1805
#define DEAL_II_HOST_DEVICE
Definition: numbers.h:35