00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__exceptions_h
00013 #define __deal2__exceptions_h
00014
00020 #include <deal.II/base/config.h>
00021
00022 #include <exception>
00023 #include <string>
00024
00025
00026
00027 #ifdef HAVE_STD_OSTREAM_HEADER
00028 # include <ostream>
00029 #else
00030 # include <iostream>
00031 #endif
00032
00033 DEAL_II_NAMESPACE_OPEN
00034
00035
00048 class ExceptionBase : public std::exception
00049 {
00050 public:
00054 ExceptionBase ();
00055
00062 ExceptionBase (const char* f, const int l, const char *func,
00063 const char* c, const char *e);
00064
00068 ExceptionBase (const ExceptionBase &exc);
00069
00081 virtual ~ExceptionBase () throw();
00082
00089 void set_fields (const char *f,
00090 const int l,
00091 const char *func,
00092 const char *c,
00093 const char *e);
00094
00099 void print_exc_data (std::ostream &out) const;
00100
00106 virtual void print_info (std::ostream &out) const;
00107
00108
00125 virtual const char * what () const throw ();
00126
00132 void print_stack_trace (std::ostream &out) const;
00133
00134 protected:
00138 const char *file;
00139
00143 unsigned int line;
00144
00148 const char *function;
00149
00153 const char *cond;
00154
00158 const char *exc;
00159
00165 char ** stacktrace;
00166
00174 int n_stacktrace_frames;
00175 };
00176
00177
00178
00179
00186 namespace deal_II_exceptions
00187 {
00188
00220 void set_additional_assert_output (const char * const p);
00221
00238 void suppress_stacktrace_in_exceptions ();
00239
00258 void disable_abort_on_exception ();
00259
00268 namespace internals
00269 {
00270
00278 void issue_error_assert (const char *file,
00279 int line,
00280 const char *function,
00281 const char *cond,
00282 const char *exc_name,
00283 ExceptionBase &e);
00284
00285
00293 template <class exc>
00294 void issue_error_throw (const char *file,
00295 int line,
00296 const char *function,
00297 const char *cond,
00298 const char *exc_name,
00299 exc e)
00300 {
00301
00302
00303 e.set_fields (file, line, function, cond, exc_name);
00304 throw e;
00305 }
00306
00307
00318 template <class exc>
00319 inline
00320 void issue_error_assert_1 (const char *file,
00321 int line,
00322 const char *function,
00323 const char *cond,
00324 const char *exc_name,
00325 exc e)
00326 {
00327 issue_error_assert (file,line,function,cond,exc_name,e);
00328 }
00329
00330
00331
00338 void abort ();
00339
00340 }
00341
00342 }
00343
00344
00345
00346 #ifdef DEBUG ////////////////////////////////////////
00347
00358 #define Assert(cond, exc) \
00359 { \
00360 if (!(cond)) \
00361 ::deal_II_exceptions::internals:: \
00362 issue_error_assert_1 (__FILE__, \
00363 __LINE__, \
00364 __PRETTY_FUNCTION__, #cond, #exc, exc);\
00365 }
00366
00367
00368 #else ////////////////////////////////////////
00369
00370 #define Assert(cond, exc) \
00371 { }
00372 #endif ////////////////////////////////////////
00373
00374
00375
00397 #ifndef DISABLE_ASSERT_THROW
00398 # ifndef HAVE_BUILTIN_EXPECT
00399 # define AssertThrow(cond, exc) \
00400 { \
00401 if (!(cond)) \
00402 ::deal_II_exceptions::internals:: \
00403 issue_error_throw (__FILE__, \
00404 __LINE__, \
00405 __PRETTY_FUNCTION__, #cond, #exc, exc); \
00406 }
00407 # else // HAVE_BUILTIN_EXPECT
00408 # define AssertThrow(cond, exc) \
00409 { \
00410 if (__builtin_expect(!(cond), false)) \
00411 ::deal_II_exceptions::internals:: \
00412 issue_error_throw (__FILE__, \
00413 __LINE__, \
00414 __PRETTY_FUNCTION__, #cond, #exc, exc); \
00415 }
00416 # endif
00417 #else
00418 # define AssertThrow(cond, exc) \
00419 { \
00420 if (!(cond)) \
00421 ::deal_II_exceptions::internals::abort (); \
00422 }
00423 #endif
00424
00425
00426
00427 #ifndef DOXYGEN
00428
00434 #define DeclException0(Exception0) \
00435 class Exception0 : public ::ExceptionBase {}
00436
00437
00438
00444 #define DeclException1(Exception1, type1, outsequence) \
00445 class Exception1 : public ::ExceptionBase { \
00446 public: \
00447 Exception1 (const type1 a1) : arg1 (a1) {} \
00448 virtual ~Exception1 () throw () {} \
00449 virtual void print_info (std::ostream &out) const { \
00450 out outsequence << std::endl; \
00451 } \
00452 private: \
00453 const type1 arg1; \
00454 }
00455
00456
00457
00463 #define DeclException2(Exception2, type1, type2, outsequence) \
00464 class Exception2 : public ::ExceptionBase { \
00465 public: \
00466 Exception2 (const type1 a1, const type2 a2) : \
00467 arg1 (a1), arg2(a2) {} \
00468 virtual ~Exception2 () throw () {} \
00469 virtual void print_info (std::ostream &out) const { \
00470 out outsequence << std::endl; \
00471 } \
00472 private: \
00473 const type1 arg1; \
00474 const type2 arg2; \
00475 }
00476
00477
00478
00484 #define DeclException3(Exception3, type1, type2, type3, outsequence) \
00485 class Exception3 : public ::ExceptionBase { \
00486 public: \
00487 Exception3 (const type1 a1, const type2 a2, const type3 a3) : \
00488 arg1 (a1), arg2(a2), arg3(a3) {} \
00489 virtual ~Exception3 () throw () {} \
00490 virtual void print_info (std::ostream &out) const { \
00491 out outsequence << std::endl; \
00492 } \
00493 private: \
00494 const type1 arg1; \
00495 const type2 arg2; \
00496 const type3 arg3; \
00497 }
00498
00499
00500
00506 #define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
00507 class Exception4 : public ::ExceptionBase { \
00508 public: \
00509 Exception4 (const type1 a1, const type2 a2, \
00510 const type3 a3, const type4 a4) : \
00511 arg1 (a1), arg2(a2), arg3(a3), arg4(a4) {} \
00512 virtual ~Exception4 () throw () {} \
00513 virtual void print_info (std::ostream &out) const { \
00514 out outsequence << std::endl; \
00515 } \
00516 private: \
00517 const type1 arg1; \
00518 const type2 arg2; \
00519 const type3 arg3; \
00520 const type4 arg4; \
00521 }
00522
00523
00524
00530 #define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence) \
00531 class Exception5 : public ::ExceptionBase { \
00532 public: \
00533 Exception5 (const type1 a1, const type2 a2, const type3 a3, \
00534 const type4 a4, const type5 a5) : \
00535 arg1 (a1), arg2(a2), arg3(a3), arg4(a4), arg5(a5) {} \
00536 virtual ~Exception5 () throw () {} \
00537 virtual void print_info (std::ostream &out) const { \
00538 out outsequence << std::endl; \
00539 } \
00540 private: \
00541 const type1 arg1; \
00542 const type2 arg2; \
00543 const type3 arg3; \
00544 const type4 arg4; \
00545 const type5 arg5; \
00546 }
00547
00548 #else // ifndef DOXYGEN
00549
00550
00556 #define DeclException0(Exception0) \
00557 static ::ExceptionBase& Exception0 ()
00558
00559
00560
00566 #define DeclException1(Exception1, type1, outsequence) \
00567 static ::ExceptionBase& Exception1 (type1 arg1) throw (errortext outsequence)
00568
00569
00570
00576 #define DeclException2(Exception2, type1, type2, outsequence) \
00577 static ::ExceptionBase& Exception2 (type1 arg1, type2 arg2) throw (errortext outsequence)
00578
00579
00580
00586 #define DeclException3(Exception3, type1, type2, type3, outsequence) \
00587 static ::ExceptionBase& Exception3 (type1 arg1, type2 arg2, type3 arg3) throw (errortext outsequence)
00588
00589
00590
00596 #define DeclException4(Exception4, type1, type2, type3, type4, outsequence) \
00597 static ::ExceptionBase& Exception4 (type1 arg1, type2 arg2, type3 arg3, type4 arg4) throw (errortext outsequence)
00598
00599
00605 #define DeclException5(Exception5, type1, type2, type3, type4, type5, outsequence) \
00606 static ::ExceptionBase& Exception5 (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) throw (errortext outsequence)
00607
00608 #endif
00609
00610
00622 namespace StandardExceptions
00623 {
00628
00641 DeclException0 (ExcDivideByZero);
00642
00654 DeclException0 (ExcNumberNotFinite);
00655
00661 DeclException0 (ExcOutOfMemory);
00662
00670 DeclException1 (ExcMemoryLeak, int,
00671 << "Destroying memory handler while " << arg1
00672 << " objects are still allocated");
00673
00678 DeclException0 (ExcIO);
00679
00687 DeclException1 (ExcFileNotOpen,
00688 char*,
00689 << "Could not open file " << arg1);
00690
00706 DeclException0 (ExcNotImplemented);
00707
00752 DeclException0 (ExcInternalError);
00753
00765 DeclException0 (ExcPureFunctionCalled);
00766
00775 DeclException0 (ExcInvalidConstructorCall);
00776
00781 DeclException0 (ExcNotInitialized);
00782
00787 DeclException0 (ExcInvalidState);
00788
00799 DeclException1 (ExcImpossibleInDim,
00800 int,
00801 << "Impossible in " << arg1 << "d.");
00802
00807 DeclException0(ExcZero);
00808
00814 DeclException0(ExcEmptyObject);
00815
00826 DeclException2 (ExcDimensionMismatch,
00827 std::size_t, std::size_t,
00828 << "Dimension " << arg1 << " not equal to " << arg2);
00829
00835 DeclException3 (ExcDimensionMismatch2,
00836 int, int, int,
00837 << "Dimension " << arg1 << " neither equal to " << arg2 << " nor to " << arg3);
00838
00856 DeclException3 (ExcIndexRange, int, int, int,
00857 << "Index " << arg1 << " is not in ["
00858 << arg2 << "," << arg3 << "[");
00859
00863 DeclException2 (ExcLowerRange, int, int,
00864 << "Number " << arg1
00865 << " must be larger or equal " << arg2);
00866
00873 DeclException2 (ExcNotMultiple, int, int,
00874 << "Division " << arg1
00875 << " by " << arg2
00876 << " has remainder different from zero");
00877
00893 DeclException0 (ExcInvalidIterator);
00894
00901 DeclException0 (ExcIteratorPastEnd);
00902
00927 DeclException1 (ExcMessage,
00928 std::string,
00929 << arg1);
00930
00936 DeclException1 (ExcCompatibility,
00937 char*,
00938 << "You are using a backward compatibility feature\n"
00939 << "that you have disabled during configuration of\n"
00940 << "the library by the --disable-compat="
00941 << arg1 << " switch. You should either use an\n"
00942 << "alternative function, or configure again without\n"
00943 << "this switch and recompile the library.");
00944
00956 DeclException0 (ExcScalarAssignmentOnlyForZeroValue);
00957
00965 DeclException0 (ExcNeedsBLAS);
00966
00974 DeclException0 (ExcNeedsLAPACK);
00975
00983 DeclException0 (ExcNeedsUMFPACK);
00984
00992 DeclException0 (ExcNeedsMETIS);
00993
01001 DeclException0 (ExcNeedsPETSC);
01002
01009 DeclException0 (ExcNeedsNetCDF);
01016 DeclException1 (ExcDisabled, char*,
01017 << "This feature was disabled by the "
01018 "configuration option --disable-"
01019 << arg1 << ". Reconfigure to use it!");
01020
01022 }
01023
01034 #define AssertDimension(dim1,dim2) Assert((dim1) == (dim2), \
01035 ExcDimensionMismatch((dim1),(dim2)))
01036
01045 #define AssertVectorVectorDimension(vec,dim1,dim2) AssertDimension((vec).size(), (dim1)) \
01046 for (unsigned int i=0;i<dim1;++i) { AssertDimension((vec)[i].size(), (dim2)); }
01047
01062 #define AssertIndexRange(index,range) Assert((index) < (range), \
01063 ExcIndexRange((index),0,(range)))
01064
01065
01066
01067
01068
01069
01070
01074 #ifdef HAVE_LIBBLAS
01075 # define AssertBLAS {}
01076 #else
01077 # define AssertBLAS Assert(false, ExcNeedsBLAS())
01078 #endif
01079
01080
01084 #ifdef HAVE_LIBLAPACK
01085 # define AssertLAPACK {}
01086 #else
01087 # define AssertLAPACK Assert(false, ExcNeedsLAPACK())
01088 #endif
01089
01090
01094 #ifdef HAVE_LIBUMFPACK
01095 # define AssertUMFPACK {}
01096 #else
01097 # define AssertUMFPACK Assert(false, ExcNeedsUMFPACK())
01098 #endif
01099
01100
01101
01102 using namespace StandardExceptions;
01103
01104
01105 DEAL_II_NAMESPACE_CLOSE
01106
01107 #endif
01108