00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef XAPIAN_INCLUDED_ERROR_H
00026 #define XAPIAN_INCLUDED_ERROR_H
00027
00028 #include <string>
00029
00030 namespace Xapian {
00031
00032 class ErrorHandler;
00033
00035
00036
00037 class Error {
00038 friend class ErrorHandler;
00039 private:
00041 std::string msg;
00042
00044 std::string context;
00045
00047 std::string type;
00048
00050 int errno_value;
00051
00053 bool has_been_handled;
00054
00056 void operator=(const Error ©me);
00057
00058 protected:
00062 Error(const std::string &msg_, const std::string &context_,
00063 const std::string &type_, int errno_value_);
00064
00065 Error(const Error &o) : msg(o.msg), context(o.context), type(o.type),
00066 errno_value(o.errno_value), has_been_handled(o.has_been_handled) {}
00067
00068 public:
00072 std::string get_msg() const
00073 {
00074 return msg;
00075 }
00076
00078 std::string get_type() const
00079 {
00080 return type;
00081 }
00082
00084 std::string get_context() const
00085 {
00086 return context;
00087 }
00088
00090 int get_errno() const
00091 {
00092 return errno_value;
00093 }
00094
00096 virtual ~Error() { }
00097 };
00098
00099 #define DEFINE_ERROR_BASECLASS(a, b) \
00100 class a : public b { \
00101 protected: \
00102 \
00103 a(const std::string &msg_, \
00104 const std::string &context_, \
00105 const std::string &type_, \
00106 int errno_value_) : b(msg_, context_, type_, errno_value_) {} \
00107 }
00108
00109 #define DEFINE_ERROR_CLASS(a, b) \
00110 class a : public b { \
00111 public: \
00112 \
00113 a(const std::string &msg_, \
00114 const std::string &context_ = "", \
00115 int errno_value_ = 0) : b(msg_, context_, #a, errno_value_) {} \
00116 \
00117 a(const std::string &msg_, \
00118 int errno_value_) : b(msg_, "", #a, errno_value_) {} \
00119 protected: \
00120 \
00121 a(const std::string &msg_, \
00122 const std::string &context_, \
00123 const std::string &type_, \
00124 int errno_value_) : b(msg_, context_, type_, errno_value_) {} \
00125 }
00126
00127 #include <xapian/errortypes.h>
00128
00129 #undef DEFINE_ERROR_BASECLASS
00130 #undef DEFINE_ERROR_CLASS
00131
00132 }
00133
00134 #endif