error_handling.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PLANCK_ERROR_HANDLING_H
00033 #define PLANCK_ERROR_HANDLING_H
00034
00035 #include <string>
00036 #include <iostream>
00037
00038 #if defined (__GNUC__)
00039 #define PLANCK_FUNC_NAME__ __PRETTY_FUNCTION__
00040 #else
00041 #define PLANCK_FUNC_NAME__ 0
00042 #endif
00043
00044 void planck_failure__(const char *file, int line, const char *func,
00045 const std::string &msg);
00046 void planck_failure__(const char *file, int line, const char *func,
00047 const char *msg);
00048 void killjob__();
00049
00050 class PlanckError
00051 {
00052 private:
00053 std::string msg;
00054
00055 public:
00056 explicit PlanckError(const std::string &message);
00057 explicit PlanckError(const char *message);
00058
00059 virtual const char* what() const
00060 { return msg.c_str(); }
00061
00062 virtual ~PlanckError();
00063 };
00064
00065
00066
00067
00068
00069 #define planck_fail(msg) \
00070 do { planck_failure__(__FILE__,__LINE__,PLANCK_FUNC_NAME__,msg); \
00071 throw PlanckError(msg); } while(0)
00072
00073
00074 #define planck_fail_quietly(msg) \
00075 do { throw PlanckError(msg); } while(0)
00076
00077
00078
00079 #define planck_assert(testval,msg) \
00080 do { if (testval); else planck_fail(msg); } while(0)
00081
00082
00083
00084
00085 #define PLANCK_DIAGNOSIS_BEGIN try {
00086
00087
00088
00089 #define PLANCK_DIAGNOSIS_END \
00090 } \
00091 catch (PlanckError &) \
00092 { killjob__(); } \
00093 catch (std::exception &e) \
00094 { std::cerr << "std::exception: " << e.what() << std::endl; killjob__(); } \
00095 catch (...) \
00096 { std::cerr << "Unknown exception" << std::endl; killjob__(); }
00097
00098
00099
00100 #endif