00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LUMIERA_ERROR_HPP_
00025 #define LUMIERA_ERROR_HPP_
00026
00027 #include <string>
00028 #include "proc/nobugcfg.hpp"
00029 #include "lib/appconfig.hpp"
00030 #include "lib/error.h"
00031
00032
00033 namespace lumiera
00034 {
00035 using std::string;
00036
00037
00038
00040 LUMIERA_ERROR_DECLARE(EXCEPTION);
00041
00049 class Error : public std::exception
00050 {
00051 public:
00052 Error (string description="", const char* id=LUMIERA_ERROR_EXCEPTION) throw();
00053 Error (std::exception& cause,
00054 string description="", const char* id=LUMIERA_ERROR_EXCEPTION) throw();
00055
00056 Error (const Error&) throw();
00057 virtual ~Error () throw() {};
00058
00060 virtual const char* what () const throw();
00061
00063 const char* getID () const throw() { return this->id_; }
00064
00066 const string& getUsermsg () const throw();
00067
00074 const string& rootCause () const throw() { return this->cause_; }
00075
00077 Error& setUsermsg (const string& newMsg) throw() { this->msg_ = newMsg; return *this; }
00078
00080 Error& prependInfo (const string& text) throw() { this->desc_.insert (0,text); return *this; }
00081
00082
00083 private:
00084 const char* id_;
00085 string msg_;
00086 string desc_;
00087 mutable string what_;
00088 const string cause_;
00089
00090 static const string extractCauseMsg (const std::exception&) throw();
00091 };
00092
00093
00094
00095
00096
00097
00098
00099
00100 namespace error
00101 {
00102
00109 void lumiera_unexpectedException () throw();
00110
00112 void assertion_terminate (const string& location);
00113
00114
00115
00116 LUMIERA_ERROR_DECLARE (LOGIC );
00117 LUMIERA_ERROR_DECLARE (FATAL );
00118 LUMIERA_ERROR_DECLARE (CONFIG );
00119 LUMIERA_ERROR_DECLARE (STATE );
00120 LUMIERA_ERROR_DECLARE (INVALID );
00121 LUMIERA_ERROR_DECLARE (EXTERNAL );
00122 LUMIERA_ERROR_DECLARE (ASSERTION);
00123
00131 #define LUMIERA_EXCEPTION_DECLARE(CLASS, PARENT, _ID_) \
00132 class CLASS : public PARENT \
00133 { \
00134 public: \
00135 CLASS (std::string description="", \
00136 const char* id=_ID_) throw() \
00137 : PARENT (description, id) {} \
00138 \
00139 CLASS (std::exception& cause, \
00140 std::string description="", \
00141 const char* id=_ID_) throw() \
00142 : PARENT (cause, description, id) {} \
00143 };
00144
00145
00146 LUMIERA_EXCEPTION_DECLARE (Logic, Error, LUMIERA_ERROR_LOGIC);
00147 LUMIERA_EXCEPTION_DECLARE (Fatal, Logic, LUMIERA_ERROR_FATAL);
00148 LUMIERA_EXCEPTION_DECLARE (Config, Error, LUMIERA_ERROR_CONFIG);
00149 LUMIERA_EXCEPTION_DECLARE (State, Error, LUMIERA_ERROR_STATE);
00150 LUMIERA_EXCEPTION_DECLARE (Invalid, Error, LUMIERA_ERROR_INVALID);
00151 LUMIERA_EXCEPTION_DECLARE (External, Error, LUMIERA_ERROR_EXTERNAL);
00152
00153
00158 void install_unexpectedException_handler ();
00159 namespace {
00160 LifecycleHook schedule_ (ON_BASIC_INIT, &install_unexpectedException_handler);
00161 }
00162
00163 }
00164
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 #ifdef NOBUG_ABORT
00174 #undef NOBUG_ABORT
00175 #define LUMIERA_NOBUG_LOCATION \
00176 std::string (NOBUG_BASENAME(__FILE__)) +":"+ NOBUG_STRINGIZE(__LINE__) + ", function " + __func__
00177 #define NOBUG_ABORT \
00178 lumiera::error::assertion_terminate (LUMIERA_NOBUG_LOCATION);
00179 #endif
00180
00181
00182 #endif // LUMIERA_ERROR_HPP_