Reference documentation for deal.II version GIT e22cb6a53e 2023-09-21 14:00: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_Core.hpp>
24 
25 #include <exception>
26 #include <ostream>
27 #include <string>
28 #include <type_traits>
29 
30 #ifdef DEAL_II_WITH_CUDA
31 # include <cusolverSp.h>
32 # include <cusparse.h>
33 #endif
34 
36 
37 
51 class ExceptionBase : public std::exception
52 {
53 public:
57  ExceptionBase();
58 
63 
67  virtual ~ExceptionBase() noexcept override = default;
68 
74  operator=(const ExceptionBase &) = delete;
75 
81  void
82  set_fields(const char *file,
83  const int line,
84  const char *function,
85  const char *cond,
86  const char *exc_name);
87 
88 
92  virtual const char *
93  what() const noexcept override;
94 
98  const char *
99  get_exc_name() const;
100 
104  void
105  print_exc_data(std::ostream &out) const;
106 
111  virtual void
112  print_info(std::ostream &out) const;
113 
118  void
119  print_stack_trace(std::ostream &out) const;
120 
121 protected:
125  const char *file;
126 
130  unsigned int line;
131 
135  const char *function;
136 
140  const char *cond;
141 
145  const char *exc;
146 
152 
153 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
157  void *raw_stacktrace[25];
158 #endif
159 
160 private:
164  void
165  generate_message() const;
166 
171  mutable std::string what_str;
172 };
173 
174 #ifndef DOXYGEN
175 
192 # define DeclException0(Exception0) \
193  class Exception0 : public ::ExceptionBase \
194  {}
195 
196 
216 # define DeclExceptionMsg(Exception, defaulttext) \
217  class Exception : public ::ExceptionBase \
218  { \
219  public: \
220  Exception(const std::string &msg = defaulttext) \
221  : arg(msg) \
222  {} \
223  virtual ~Exception() noexcept \
224  {} \
225  virtual void \
226  print_info(std::ostream &out) const override \
227  { \
228  out << " " << arg << std::endl; \
229  } \
230  \
231  private: \
232  const std::string arg; \
233  }
234 
252 # define DeclException1(Exception1, type1, outsequence) \
253  class Exception1 : public ::ExceptionBase \
254  { \
255  public: \
256  Exception1(type1 const &a1) \
257  : arg1(a1) \
258  {} \
259  virtual ~Exception1() noexcept \
260  {} \
261  virtual void \
262  print_info(std::ostream &out) const override \
263  { \
264  out << " " outsequence << std::endl; \
265  } \
266  \
267  private: \
268  type1 const arg1; \
269  }
270 
271 
289 # define DeclException2(Exception2, type1, type2, outsequence) \
290  class Exception2 : public ::ExceptionBase \
291  { \
292  public: \
293  Exception2(type1 const &a1, type2 const &a2) \
294  : arg1(a1) \
295  , arg2(a2) \
296  {} \
297  virtual ~Exception2() noexcept \
298  {} \
299  virtual void \
300  print_info(std::ostream &out) const override \
301  { \
302  out << " " outsequence << std::endl; \
303  } \
304  \
305  private: \
306  type1 const arg1; \
307  type2 const arg2; \
308  }
309 
310 
328 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
329  class Exception3 : public ::ExceptionBase \
330  { \
331  public: \
332  Exception3(type1 const &a1, type2 const &a2, type3 const &a3) \
333  : arg1(a1) \
334  , arg2(a2) \
335  , arg3(a3) \
336  {} \
337  virtual ~Exception3() noexcept \
338  {} \
339  virtual void \
340  print_info(std::ostream &out) const override \
341  { \
342  out << " " outsequence << std::endl; \
343  } \
344  \
345  private: \
346  type1 const arg1; \
347  type2 const arg2; \
348  type3 const arg3; \
349  }
350 
351 
369 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
370  class Exception4 : public ::ExceptionBase \
371  { \
372  public: \
373  Exception4(type1 const &a1, \
374  type2 const &a2, \
375  type3 const &a3, \
376  type4 const &a4) \
377  : arg1(a1) \
378  , arg2(a2) \
379  , arg3(a3) \
380  , arg4(a4) \
381  {} \
382  virtual ~Exception4() noexcept \
383  {} \
384  virtual void \
385  print_info(std::ostream &out) const override \
386  { \
387  out << " " outsequence << std::endl; \
388  } \
389  \
390  private: \
391  type1 const arg1; \
392  type2 const arg2; \
393  type3 const arg3; \
394  type4 const arg4; \
395  }
396 
397 
415 # define DeclException5( \
416  Exception5, type1, type2, type3, type4, type5, outsequence) \
417  class Exception5 : public ::ExceptionBase \
418  { \
419  public: \
420  Exception5(type1 const &a1, \
421  type2 const &a2, \
422  type3 const &a3, \
423  type4 const &a4, \
424  type5 const &a5) \
425  : arg1(a1) \
426  , arg2(a2) \
427  , arg3(a3) \
428  , arg4(a4) \
429  , arg5(a5) \
430  {} \
431  virtual ~Exception5() noexcept \
432  {} \
433  virtual void \
434  print_info(std::ostream &out) const override \
435  { \
436  out << " " outsequence << std::endl; \
437  } \
438  \
439  private: \
440  type1 const arg1; \
441  type2 const arg2; \
442  type3 const arg3; \
443  type4 const arg4; \
444  type5 const arg5; \
445  }
446 
447 #else /*ifndef DOXYGEN*/
448 
449 // Dummy definitions for doxygen:
450 
467 # define DeclException0(Exception0) \
468  \
469  static ::ExceptionBase &Exception0()
470 
490 # define DeclExceptionMsg(Exception, defaulttext) \
491  \
492  \
493  static ::ExceptionBase &Exception()
494 
512 # define DeclException1(Exception1, type1, outsequence) \
513  \
514  \
515  static ::ExceptionBase &Exception1(type1 arg1)
516 
517 
535 # define DeclException2(Exception2, type1, type2, outsequence) \
536  \
537  \
538  static ::ExceptionBase &Exception2(type1 arg1, type2 arg2)
539 
540 
558 # define DeclException3(Exception3, type1, type2, type3, outsequence) \
559  \
560  \
561  static ::ExceptionBase &Exception3(type1 arg1, type2 arg2, type3 arg3)
562 
563 
581 # define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
582  \
583  \
584  static ::ExceptionBase &Exception4(type1 arg1, \
585  type2 arg2, \
586  type3 arg3, \
587  type4 arg4)
588 
589 
607 # define DeclException5( \
608  Exception5, type1, type2, type3, type4, type5, outsequence) \
609  \
610  \
611  static ::ExceptionBase &Exception5( \
612  type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)
613 
614 #endif /*ifndef DOXYGEN*/
615 
616 
629 {
639  "A piece of code is attempting a division by zero. This is "
640  "likely going to lead to results that make no sense.");
641 
654  std::complex<double>,
655  << "In a significant number of places, deal.II checks that some intermediate "
656  << "value is a finite number (as opposed to plus or minus infinity, or "
657  << "NaN/Not a Number). In the current function, we encountered a number "
658  << "that is not finite (its value is " << arg1 << " and therefore "
659  << "violates the current assertion).\n\n"
660  << "This may be due to the fact that some operation in this function "
661  << "created such a value, or because one of the arguments you passed "
662  << "to the function already had this value from some previous "
663  << "operation. In the latter case, this function only triggered the "
664  << "error but may not actually be responsible for the computation of "
665  << "the number that is not finite.\n\n"
666  << "There are two common cases where this situation happens. First, your "
667  << "code (or something in deal.II) divides by zero in a place where this "
668  << "should not happen. Or, you are trying to solve a linear system "
669  << "with an unsuitable solver (such as an indefinite or non-symmetric "
670  << "linear system using a Conjugate Gradient solver); such attempts "
671  << "oftentimes yield an operation somewhere that tries to divide "
672  << "by zero or take the square root of a negative value.\n\n"
673  << "In any case, when trying to find the source of the error, "
674  << "recall that the location where you are getting this error is "
675  << "simply the first place in the program where there is a check "
676  << "that a number (e.g., an element of a solution vector) is in fact "
677  << "finite, but that the actual error that computed the number "
678  << "may have happened far earlier. To find this location, you "
679  << "may want to add checks for finiteness in places of your "
680  << "program visited before the place where this error is produced. "
681  << "One way to check for finiteness is to use the 'AssertIsFinite' "
682  << "macro.");
683 
688  std::size_t,
689  "Your program tried to allocate some memory but this "
690  "allocation failed. Typically, this either means that "
691  "you simply do not have enough memory in your system, "
692  "or that you are (erroneously) trying to allocate "
693  "a chunk of memory that is simply beyond all reasonable "
694  "size, for example because the size of the object has "
695  "been computed incorrectly."
696  "\n\n"
697  "In the current case, the request was for "
698  << arg1 << " bytes.");
699 
705  int,
706  << "Destroying memory handler while " << arg1
707  << " objects are still allocated.");
708 
713  "An input/output error has occurred. There are a number of "
714  "reasons why this may be happening, both for reading and "
715  "writing operations."
716  "\n\n"
717  "If this happens during an operation that tries to read "
718  "data: First, you may be "
719  "trying to read from a file that doesn't exist or that is "
720  "not readable given its file permissions. Second, deal.II "
721  "uses this error at times if it tries to "
722  "read information from a file but where the information "
723  "in the file does not correspond to the expected format. "
724  "An example would be a truncated file, or a mesh file "
725  "that contains not only sections that describe the "
726  "vertices and cells, but also sections for additional "
727  "data that deal.II does not understand."
728  "\n\n"
729  "If this happens during an operation that tries to write "
730  "data: you may be trying to write to a file to which file "
731  "or directory permissions do not allow you to write. A "
732  "typical example is where you specify an output file in "
733  "a directory that does not exist.");
734 
742  std::string,
743  << "Could not open file " << arg1
744  << "."
745  "\n\n"
746  "If this happens during an operation that tries to read "
747  "data: you may be "
748  "trying to read from a file that doesn't exist or that is "
749  "not readable given its file permissions."
750  "\n\n"
751  "If this happens during an operation that tries to write "
752  "data: you may be trying to write to a file to which file "
753  "or directory permissions do not allow you to write. A "
754  "typical example is where you specify an output file in "
755  "a directory that does not exist.");
756 
766  "You are trying to use functionality in deal.II that is "
767  "currently not implemented. In many cases, this indicates "
768  "that there simply didn't appear much of a need for it, or "
769  "that the author of the original code did not have the "
770  "time to implement a particular case. If you hit this "
771  "exception, it is therefore worth the time to look into "
772  "the code to find out whether you may be able to "
773  "implement the missing functionality. If you do, please "
774  "consider providing a patch to the deal.II development "
775  "sources (see the deal.II website on how to contribute).");
776 
798  "This exception -- which is used in many places in the "
799  "library -- usually indicates that some condition which "
800  "the author of the code thought must be satisfied at a "
801  "certain point in an algorithm, is not fulfilled. An "
802  "example would be that the first part of an algorithm "
803  "sorts elements of an array in ascending order, and "
804  "a second part of the algorithm later encounters an "
805  "element that is not larger than the previous one."
806  "\n\n"
807  "There is usually not very much you can do if you "
808  "encounter such an exception since it indicates an error "
809  "in deal.II, not in your own program. Try to come up with "
810  "the smallest possible program that still demonstrates "
811  "the error and contact the deal.II mailing lists with it "
812  "to obtain help.");
813 
822  "You (or a place in the library) are trying to call a "
823  "function that is declared as a virtual function in a "
824  "base class but that has not been overridden in your "
825  "derived class."
826  "\n\n"
827  "This exception happens in cases where the base class "
828  "cannot provide a useful default implementation for "
829  "the virtual function, but where we also do not want "
830  "to mark the function as abstract (i.e., with '=0' at the end) "
831  "because the function is not essential to the class in many "
832  "contexts. In cases like this, the base class provides "
833  "a dummy implementation that makes the compiler happy, but "
834  "that then throws the current exception."
835  "\n\n"
836  "A concrete example would be the 'Function' class. It declares "
837  "the existence of 'value()' and 'gradient()' member functions, "
838  "and both are marked as 'virtual'. Derived classes have to "
839  "override these functions for the values and gradients of a "
840  "particular function. On the other hand, not every function "
841  "has a gradient, and even for those that do, not every program "
842  "actually needs to evaluate it. Consequently, there is no "
843  "*requirement* that a derived class actually override the "
844  "'gradient()' function (as there would be had it been marked "
845  "as abstract). But, since the base class cannot know how to "
846  "compute the gradient, if a derived class does not override "
847  "the 'gradient()' function and it is called anyway, then the "
848  "default implementation in the base class will simply throw "
849  "an exception."
850  "\n\n"
851  "The exception you see is what happens in cases such as the "
852  "one just illustrated. To fix the problem, you need to "
853  "investigate whether the function being called should indeed have "
854  "been called; if the answer is 'yes', then you need to "
855  "implement the missing override in your class.");
856 
861  std::string,
862  << "Please provide an implementation for the function \""
863  << arg1 << "\"");
864 
870  std::string,
871  int,
872  << "The function \"" << arg1 << "\" returned the nonzero value " << arg2
873  << ", but the calling site expected the return value to be zero. "
874  "This error often happens when the function in question is a 'callback', "
875  "that is a user-provided function called from somewhere within deal.II "
876  "or within an external library such as PETSc, Trilinos, SUNDIALS, etc., "
877  "that expect these callbacks to indicate errors via nonzero return "
878  "codes.");
879 
884 
889 
897  int,
898  << "You are trying to execute functionality that is "
899  << "impossible in " << arg1
900  << "d or simply does not make any sense.");
901 
910  int,
911  int,
912  << "You are trying to execute functionality that is "
913  << "impossible in dimensions <" << arg1 << ',' << arg2
914  << "> or simply does not make any sense.");
915 
916 
921  "In a check in the code, deal.II encountered a zero in "
922  "a place where this does not make sense. See the condition "
923  "that was being checked and that is printed further up "
924  "in the error message to get more information on what "
925  "the erroneous zero corresponds to.");
926 
932  "The object you are trying to access is empty but it makes "
933  "no sense to attempt the operation you are trying on an "
934  "empty object.");
935 
944  std::size_t,
945  std::size_t,
946  << "Two sizes or dimensions were supposed to be equal, "
947  << "but aren't. They are " << arg1 << " and " << arg2 << '.');
948 
954  std::size_t,
955  std::size_t,
956  std::size_t,
957  << "The size or dimension of one object, " << arg1
958  << " was supposed to be "
959  << "equal to one of two values, but isn't. The two possible "
960  << "values are " << arg2 << " and " << arg3 << '.');
961 
976  std::size_t,
977  std::size_t,
978  std::size_t,
979  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
980  << arg3 << ")."
981  << (arg2 == arg3 ?
982  " In the current case, this half-open range is in fact empty, "
983  "suggesting that you are accessing an element of an empty "
984  "collection such as a vector that has not been set to the "
985  "correct size." :
986  ""));
987 
1003  template <typename T>
1006  T,
1007  T,
1008  T,
1009  << "Index " << arg1 << " is not in the half-open range [" << arg2 << ','
1010  << arg3 << ")."
1011  << (arg2 == arg3 ?
1012  " In the current case, this half-open range is in fact empty, "
1013  "suggesting that you are accessing an element of an empty "
1014  "collection such as a vector that has not been set to the "
1015  "correct size." :
1016  ""));
1017 
1022  int,
1023  int,
1024  << "Number " << arg1 << " must be larger than or equal "
1025  << arg2 << '.');
1026 
1030  template <typename T>
1032  T,
1033  T,
1034  << "Number " << arg1 << " must be larger than or equal "
1035  << arg2 << '.');
1036 
1042  int,
1043  int,
1044  << "Division " << arg1 << " by " << arg2
1045  << " has remainder different from zero.");
1046 
1056  "You are trying to use an iterator, but the iterator is "
1057  "in an invalid state. This may indicate that the iterator "
1058  "object has not been initialized, or that it has been "
1059  "moved beyond the end of the range of valid elements.");
1060 
1066  "You are trying to use an iterator, but the iterator is "
1067  "pointing past the end of the range of valid elements. "
1068  "It is not valid to dereference the iterator in this "
1069  "case.");
1070 
1084  DeclException1(ExcMessage, std::string, << arg1);
1085 
1090  "You are trying an operation on a vector that is only "
1091  "allowed if the vector has no ghost elements, but the "
1092  "vector you are operating on does have ghost elements. "
1093  "Specifically, vectors with ghost elements are read-only "
1094  "and cannot appear in operations that write into these "
1095  "vectors."
1096  "\n\n"
1097  "See the glossary entry on 'Ghosted vectors' for more "
1098  "information.");
1099 
1105  int,
1106  << "Something went wrong when making cell " << arg1
1107  << ". Read the docs and the source code "
1108  << "for more information.");
1109 
1118  "You are trying an operation of the form 'vector = C', "
1119  "'matrix = C', or 'tensor = C' with a nonzero scalar value "
1120  "'C'. However, such assignments are only allowed if the "
1121  "C is zero, since the semantics for assigning any other "
1122  "value are not clear. For example: one could interpret "
1123  "assigning a matrix a value of 1 to mean the matrix has a "
1124  "norm of 1, the matrix is the identity matrix, or the "
1125  "matrix contains only 1s. Similar problems exist with "
1126  "vectors and tensors. Hence, to avoid this ambiguity, such "
1127  "assignments are not permitted.");
1128 
1134  "You are attempting to use functionality that is only available "
1135  "if deal.II was configured to use LAPACK, but cmake did not "
1136  "find a valid LAPACK library.");
1137 
1142  ExcNeedsHDF5,
1143  "You are attempting to use functionality that requires that deal.II is configured "
1144  "with HDF5 support. However, when you called 'cmake', HDF5 support "
1145  "was not detected.");
1146 
1151  ExcNeedsMPI,
1152  "You are attempting to use functionality that is only available "
1153  "if deal.II was configured to use MPI.");
1154 
1160  "You are attempting to use functionality that is only available "
1161  "if deal.II was configured to use the function parser which "
1162  "relies on the muparser library, but cmake did not "
1163  "find a valid muparser library on your system and also did "
1164  "not choose the one that comes bundled with deal.II.");
1165 
1171  "You are attempting to use functionality that is only available "
1172  "if deal.II was configured to use Assimp, but cmake did not "
1173  "find a valid Assimp library.");
1174 
1175 #ifdef DEAL_II_WITH_CUDA
1182  DeclException1(ExcCudaError, const char *, << arg1);
1187  std::string,
1188  << "There was an error in a cuSPARSE function: " << arg1);
1189 #endif
1197  "You are attempting to use functionality that is only available if deal.II "
1198  "was configured to use Trilinos' SEACAS library (which provides ExodusII), "
1199  "but cmake did not find a valid SEACAS library.");
1200 
1205  ExcNeedsCGAL,
1206  "You are attempting to use functionality that is only available "
1207  "if deal.II was configured to use CGAL, but cmake did not "
1208  "find a valid CGAL library.");
1209 
1210 #ifdef DEAL_II_WITH_MPI
1232  class ExcMPI : public ::ExceptionBase
1233  {
1234  public:
1235  ExcMPI(const int error_code);
1236 
1237  virtual void
1238  print_info(std::ostream &out) const override;
1239 
1240  const int error_code;
1241  };
1242 #endif // DEAL_II_WITH_MPI
1243 
1244 
1245 
1246 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
1255  class ExcExodusII : public ExceptionBase
1256  {
1257  public:
1263  ExcExodusII(const int error_code);
1264 
1268  virtual void
1269  print_info(std::ostream &out) const override;
1270 
1274  const int error_code;
1275  };
1276 #endif // DEAL_II_TRILINOS_WITH_SEACAS
1277 
1284  "A user call-back function encountered a recoverable error, "
1285  "but the underlying library that called the call-back did not "
1286  "manage to recover from the error and aborted its operation."
1287  "\n\n"
1288  "See the glossary entry on user call-back functions for more "
1289  "information.");
1290 } /*namespace StandardExceptions*/
1291 
1292 
1293 
1301 {
1302  namespace internals
1303  {
1311  extern bool allow_abort_on_exception;
1312  } // namespace internals
1313 
1332  void
1333  set_additional_assert_output(const char *const p);
1334 
1345  void
1347 
1362  void
1364 
1373  void
1375 
1383  namespace internals
1384  {
1389  [[noreturn]] void
1390  abort(const ExceptionBase &exc) noexcept;
1391 
1396  {
1407  };
1408 
1426  template <typename ExceptionType>
1427  [[noreturn]] void
1429  const char *file,
1430  int line,
1431  const char *function,
1432  const char *cond,
1433  const char *exc_name,
1434  ExceptionType e)
1435  {
1436  // Fill the fields of the exception object
1437  e.set_fields(file, line, function, cond, exc_name);
1438 
1439  switch (handling)
1440  {
1442  {
1446  else
1447  {
1448  // We are not allowed to abort, so just throw the error:
1449  throw e;
1450  }
1451  }
1453  throw e;
1454  // this function should never return (and AssertNothrow can);
1455  // something must have gone wrong in the error handling code for us
1456  // to get this far, so throw an exception.
1457  default:
1459  }
1460  }
1461 
1465  void
1466  do_issue_error_nothrow(const ExceptionBase &e) noexcept;
1467 
1476  template <typename ExceptionType>
1477  void
1478  issue_error_nothrow(const char *file,
1479  int line,
1480  const char *function,
1481  const char *cond,
1482  const char *exc_name,
1483  ExceptionType e) noexcept
1484  {
1485  static_assert(std::is_base_of_v<ExceptionBase, ExceptionType>,
1486  "The provided exception must inherit from ExceptionBase.");
1487  // Fill the fields of the exception object
1488  e.set_fields(file, line, function, cond, exc_name);
1489  // avoid moving a bunch of code into the header by dispatching to
1490  // another function:
1492  }
1493 #ifdef DEAL_II_WITH_CUDA
1499  std::string
1500  get_cusparse_error_string(const cusparseStatus_t error_code);
1501 
1507  std::string
1508  get_cusolver_error_string(const cusolverStatus_t error_code);
1509 #endif
1510  } /*namespace internals*/
1511 
1512 } /*namespace deal_II_exceptions*/
1513 
1514 
1515 
1541 #ifdef DEBUG
1542 # if KOKKOS_VERSION >= 30600
1543 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1544 # define Assert(cond, exc) \
1545  { \
1546  KOKKOS_IF_ON_HOST(({ \
1547  if (__builtin_expect(!(cond), false)) \
1548  ::deal_II_exceptions::internals::issue_error_noreturn( \
1549  ::deal_II_exceptions::internals::ExceptionHandling:: \
1550  abort_or_throw_on_exception, \
1551  __FILE__, \
1552  __LINE__, \
1553  __PRETTY_FUNCTION__, \
1554  #cond, \
1555  #exc, \
1556  exc); \
1557  })) \
1558  KOKKOS_IF_ON_DEVICE(({ \
1559  if (!(cond)) \
1560  Kokkos::abort(#cond); \
1561  })) \
1562  }
1563 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1564 # define Assert(cond, exc) \
1565  { \
1566  KOKKOS_IF_ON_HOST(({ \
1567  if (!(cond)) \
1568  ::deal_II_exceptions::internals::issue_error_noreturn( \
1569  ::deal_II_exceptions::internals::ExceptionHandling:: \
1570  abort_or_throw_on_exception, \
1571  __FILE__, \
1572  __LINE__, \
1573  __PRETTY_FUNCTION__, \
1574  #cond, \
1575  #exc, \
1576  exc); \
1577  })) \
1578  KOKKOS_IF_ON_DEVICE(({ \
1579  if (!(cond)) \
1580  Kokkos::abort(#cond); \
1581  })) \
1582  }
1583 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1584 # else /*if KOKKOS_VERSION >= 30600*/
1585 # ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1586 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1587 # define Assert(cond, exc) \
1588  { \
1589  if (__builtin_expect(!(cond), false)) \
1590  ::deal_II_exceptions::internals::issue_error_noreturn( \
1591  ::deal_II_exceptions::internals::ExceptionHandling:: \
1592  abort_or_throw_on_exception, \
1593  __FILE__, \
1594  __LINE__, \
1595  __PRETTY_FUNCTION__, \
1596  #cond, \
1597  #exc, \
1598  exc); \
1599  }
1600 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1601 # define Assert(cond, exc) \
1602  { \
1603  if (!(cond)) \
1604  ::deal_II_exceptions::internals::issue_error_noreturn( \
1605  ::deal_II_exceptions::internals::ExceptionHandling:: \
1606  abort_or_throw_on_exception, \
1607  __FILE__, \
1608  __LINE__, \
1609  __PRETTY_FUNCTION__, \
1610  #cond, \
1611  #exc, \
1612  exc); \
1613  }
1614 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1615 # else /*#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1616 # define Assert(cond, exc) \
1617  { \
1618  if (!(cond)) \
1619  Kokkos::abort(#cond); \
1620  }
1621 # endif /*ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1622 # endif /*KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
1623 #else /*ifdef DEBUG*/
1624 # define Assert(cond, exc) \
1625  {}
1626 #endif /*ifdef DEBUG*/
1627 
1628 
1629 
1656 #ifdef DEBUG
1657 # ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1658 # define AssertNothrow(cond, exc) \
1659  { \
1660  if (__builtin_expect(!(cond), false)) \
1661  ::deal_II_exceptions::internals::issue_error_nothrow( \
1662  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1663  }
1664 # else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1665 # define AssertNothrow(cond, exc) \
1666  { \
1667  if (!(cond)) \
1668  ::deal_II_exceptions::internals::issue_error_nothrow( \
1669  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
1670  }
1671 # endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1672 #else
1673 # define AssertNothrow(cond, exc) \
1674  {}
1675 #endif
1676 
1704 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT
1705 # define AssertThrow(cond, exc) \
1706  { \
1707  if (__builtin_expect(!(cond), false)) \
1708  ::deal_II_exceptions::internals::issue_error_noreturn( \
1709  ::deal_II_exceptions::internals::ExceptionHandling:: \
1710  throw_on_exception, \
1711  __FILE__, \
1712  __LINE__, \
1713  __PRETTY_FUNCTION__, \
1714  #cond, \
1715  #exc, \
1716  exc); \
1717  }
1718 #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1719 # define AssertThrow(cond, exc) \
1720  { \
1721  if (!(cond)) \
1722  ::deal_II_exceptions::internals::issue_error_noreturn( \
1723  ::deal_II_exceptions::internals::ExceptionHandling:: \
1724  throw_on_exception, \
1725  __FILE__, \
1726  __LINE__, \
1727  __PRETTY_FUNCTION__, \
1728  #cond, \
1729  #exc, \
1730  exc); \
1731  }
1732 #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
1733 
1734 
1735 namespace deal_II_exceptions
1736 {
1737  namespace internals
1738  {
1744  template <typename T, typename U>
1745  inline DEAL_II_HOST_DEVICE constexpr bool
1746  compare_for_equality(const T &t, const U &u)
1747  {
1748  using common_type = std::common_type_t<T, U>;
1749  return static_cast<common_type>(t) == static_cast<common_type>(u);
1750  }
1751 
1752 
1758  template <typename T, typename U>
1759  inline DEAL_II_HOST_DEVICE constexpr bool
1760  compare_less_than(const T &t, const U &u)
1761  {
1762  using common_type = std::common_type_t<T, U>;
1763  return (static_cast<common_type>(t) < static_cast<common_type>(u));
1764  }
1765  } // namespace internals
1766 } // namespace deal_II_exceptions
1767 
1768 
1789 #define AssertDimension(dim1, dim2) \
1790  Assert(::deal_II_exceptions::internals::compare_for_equality(dim1, \
1791  dim2), \
1792  ::ExcDimensionMismatch((dim1), (dim2)))
1793 
1794 
1812 #define AssertVectorVectorDimension(VEC, DIM1, DIM2) \
1813  AssertDimension(VEC.size(), DIM1); \
1814  for (const auto &subvector : VEC) \
1815  { \
1816  (void)subvector; \
1817  AssertDimension(subvector.size(), DIM2); \
1818  }
1819 
1820 namespace internal
1821 {
1822  // Workaround to allow for commas in template parameter lists
1823  // in preprocessor macros as found in
1824  // https://stackoverflow.com/questions/13842468/comma-in-c-c-macro
1825  template <typename F>
1827 
1828  template <typename T, typename U>
1829  struct argument_type<T(U)>
1830  {
1831  using type = U;
1832  };
1833 
1834  template <typename F>
1836 } // namespace internal
1837 
1857 #define AssertIndexRange(index, range) \
1858  Assert(::deal_II_exceptions::internals::compare_less_than(index, \
1859  range), \
1860  ExcIndexRangeType<::internal::argument_type_t<void( \
1861  std::common_type_t<decltype(index), decltype(range)>)>>((index), \
1862  0, \
1863  (range)))
1864 
1884 #define AssertIsFinite(number) \
1885  Assert(::numbers::is_finite(number), \
1886  ::ExcNumberNotFinite(std::complex<double>(number)))
1887 
1893 #define AssertIsNotUsed(obj) Assert((obj)->used() == false, ExcInternalError())
1894 
1895 #ifdef DEAL_II_WITH_MPI
1916 # define AssertThrowMPI(error_code) \
1917  AssertThrow(error_code == MPI_SUCCESS, ::ExcMPI(error_code))
1918 #else
1919 # define AssertThrowMPI(error_code) \
1920  {}
1921 #endif // DEAL_II_WITH_MPI
1922 
1923 #ifdef DEAL_II_WITH_CUDA
1941 # ifdef DEBUG
1942 # define AssertCuda(error_code) \
1943  Assert(error_code == cudaSuccess, \
1944  ::ExcCudaError(cudaGetErrorString(error_code)))
1945 # else
1946 # define AssertCuda(error_code) \
1947  { \
1948  (void)(error_code); \
1949  }
1950 # endif
1951 
1968 # ifdef DEBUG
1969 # define AssertNothrowCuda(error_code) \
1970  AssertNothrow(error_code == cudaSuccess, \
1971  ::ExcCudaError(cudaGetErrorString(error_code)))
1972 # else
1973 # define AssertNothrowCuda(error_code) \
1974  { \
1975  (void)(error_code); \
1976  }
1977 # endif
1978 
1996 # ifdef DEBUG
1997 # define AssertCudaKernel() \
1998  { \
1999  cudaError_t local_error_code = cudaPeekAtLastError(); \
2000  AssertCuda(local_error_code); \
2001  local_error_code = cudaDeviceSynchronize(); \
2002  AssertCuda(local_error_code) \
2003  }
2004 # else
2005 # define AssertCudaKernel() \
2006  {}
2007 # endif
2008 
2026 # ifdef DEBUG
2027 # define AssertCusparse(error_code) \
2028  Assert( \
2029  error_code == CUSPARSE_STATUS_SUCCESS, \
2030  ExcCusparseError( \
2031  deal_II_exceptions::internals::get_cusparse_error_string( \
2032  error_code)))
2033 # else
2034 # define AssertCusparse(error_code) \
2035  { \
2036  (void)(error_code); \
2037  }
2038 # endif
2039 
2056 # ifdef DEBUG
2057 # define AssertNothrowCusparse(error_code) \
2058  AssertNothrow( \
2059  error_code == CUSPARSE_STATUS_SUCCESS, \
2060  ExcCusparseError( \
2061  deal_II_exceptions::internals::get_cusparse_error_string( \
2062  error_code)))
2063 # else
2064 # define AssertNothrowCusparse(error_code) \
2065  { \
2066  (void)(error_code); \
2067  }
2068 # endif
2069 
2087 # ifdef DEBUG
2088 # define AssertCusolver(error_code) \
2089  Assert( \
2090  error_code == CUSOLVER_STATUS_SUCCESS, \
2091  ExcCusparseError( \
2092  deal_II_exceptions::internals::get_cusolver_error_string( \
2093  error_code)))
2094 # else
2095 # define AssertCusolver(error_code) \
2096  { \
2097  (void)(error_code); \
2098  }
2099 # endif
2100 
2101 #endif
2102 
2103 #ifdef DEAL_II_TRILINOS_WITH_SEACAS
2121 # define AssertThrowExodusII(error_code) \
2122  AssertThrow(error_code == 0, \
2123  ::StandardExceptions::ExcExodusII(error_code));
2124 #endif // DEAL_II_TRILINOS_WITH_SEACAS
2125 
2126 using namespace StandardExceptions;
2127 
2129 
2130 #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:125
std::string what_str
Definition: exceptions.h:171
const char * get_exc_name() const
Definition: exceptions.cc:173
virtual ~ExceptionBase() noexcept override=default
int n_stacktrace_frames
Definition: exceptions.h:151
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:145
const char * function
Definition: exceptions.h:135
void print_exc_data(std::ostream &out) const
Definition: exceptions.cc:181
unsigned int line
Definition: exceptions.h:130
void * raw_stacktrace[25]
Definition: exceptions.h:157
const char * cond
Definition: exceptions.h:140
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:467
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:535
static ::ExceptionBase & ExcEmptyObject()
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:490
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:558
static ::ExceptionBase & ExcCusparseError(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:512
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:1760
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:1746
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:1428
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:1478
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:1835
#define DEAL_II_HOST_DEVICE
Definition: numbers.h:35