00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _EXCEPTION_HPP
00013 #define _EXCEPTION_HPP
00014 #include <iostream>
00015 #include <string>
00016 #include <sstream>
00017 using namespace std;
00018
00019 namespace lemur
00020 {
00021 namespace api
00022 {
00024 typedef unsigned long LemurErrorType;
00026
00072 class Exception {
00073 public:
00074 Exception(const char *throwerString=" unknown thrower", const char *whatString="unknown exception") {
00075 _what = throwerString;
00076 _what += ": ";
00077 _what += whatString;
00078 }
00079
00080 Exception( const std::string& whoString, int whereLine,
00081 const std::string& whatString, LemurErrorType code )
00082 {
00083 std::stringstream lineString;
00084 lineString << whereLine;
00085
00086 _what = whoString + "(" + lineString.str() + ")" + ": " + whatString;
00087 _code = code;
00088 }
00089
00090 Exception( const std::string& whoString, int whereLine,
00091 const std::string& whatString, const Exception& inner )
00092 {
00093 std::stringstream lineString;
00094 lineString << whereLine;
00095
00096 _what = whoString + "(" + lineString.str() + "): " + whatString + "\n\t" + inner.what();
00097 _code = inner.code();
00098 }
00099
00100 ~Exception() {}
00101
00102 inline void writeMessage(std::ostream &os = std::cerr)
00103 {
00104 os << "Exception [code = " << _code << "]" << std::endl << _what << std::endl;
00105 }
00106
00107 const std::string& what() const {
00108 return _what;
00109 }
00110
00111 LemurErrorType code() const {
00112 return _code;
00113 }
00114
00115 private:
00116 std::string _what;
00117 LemurErrorType _code;
00118 };
00119
00120 #define LEMUR_ABORT( e ) { std::cerr << e.what() << std::endl; exit(-1); }
00121 #define LEMUR_THROW_LINE( code, text, file, line ) throw lemur::api::Exception( file, line, std::string() + text, (code) )
00122 #define LEMUR_THROW(code, text) LEMUR_THROW_LINE(code, text, __FILE__, __LINE__)
00123 #define LEMUR_RETHROW_LINE( e, text, file, line ) throw lemur::api::Exception( file, line, (std::string() + text), (e) )
00124 #define LEMUR_RETHROW( e, text) LEMUR_RETHROW_LINE(e, text, __FILE__, __LINE__)
00125
00126 #define LEMUR_GENERIC_ERROR ((lemur::api::LemurErrorType)0xFFFFFFFF)
00127 #define LEMUR_MISSING_PARAMETER_ERROR ((lemur::api::LemurErrorType)0xFFFFFFFE)
00128 #define LEMUR_BAD_PARAMETER_ERROR ((lemur::api::LemurErrorType)0xFFFFFFF7)
00129 #define LEMUR_PARSE_ERROR ((lemur::api::LemurErrorType)0xFFFFFFFD)
00130 #define LEMUR_KEYFILE_IO_ERROR ((lemur::api::LemurErrorType)0xFFFFFFFC)
00131 #define LEMUR_IO_ERROR ((lemur::api::LemurErrorType)0xFFFFFFFB)
00132 #define LEMUR_RUNTIME_ERROR ((lemur::api::LemurErrorType)0xFFFFFFFA)
00133 #define LEMUR_NETWORK_ERROR ((lemur::api::LemurErrorType)0xFFFFFFF9)
00134 #define LEMUR_INTERNAL_ERROR ((lemur::api::LemurErrorType)0xFFFFFFF8)
00135 }
00136 }
00137
00138 #endif