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
00033
00034
00035
00036
00037
00039
00040 #ifndef __SPHINXERROR_H__
00041 #define __SPHINXERROR_H__
00042
00043 #include <string>
00044 #include <exception>
00045
00046 #include <sstream>
00047 #include <errno.h>
00048 #include <string.h>
00049 namespace Sphinx
00050 {
00051
00052
00053
00063 enum ErrorType_t {
00064 STATUS_OK = 0,
00065 CONNECTION_ERROR = 1,
00066 SERVER_ERROR = 2,
00067 MESSAGE_ERROR = 3,
00068 VALUE_TYPE_ERROR = 4,
00069 CLIENT_USAGE_ERROR = 5
00070 };
00071
00080 struct Error_t : public std::exception
00081 {
00082 std::string errMsg;
00083 ErrorType_t errCode;
00084
00085 Error_t(ErrorType_t err, const std::string &msg)
00086 :std::exception(),errMsg(msg),errCode(err)
00087 {}
00088
00089 virtual const char* what() const throw() {
00090 return errMsg.c_str();
00091 }
00092
00093 virtual ~Error_t() throw(){}
00094 };
00095
00096
00105 struct Warning_t : public std::exception
00106 {
00107 std::string errMsg;
00108
00109 Warning_t(const std::string &msg) : std::exception() ,errMsg(msg)
00110 {}
00111
00112 virtual const char* what() const throw() {
00113 return errMsg.c_str();
00114 }
00115
00116 virtual ~Warning_t() throw(){}
00117 };
00118
00119
00125 struct ServerError_t : public Error_t
00126 {
00127 ServerError_t(const std::string &msg)
00128 :Error_t(SERVER_ERROR, msg) {}
00129 };
00130
00136 struct MessageError_t : public Error_t
00137 {
00138 MessageError_t(const std::string &msg)
00139 :Error_t(MESSAGE_ERROR, msg) {}
00140 };
00141
00147 struct ConnectionError_t : public Error_t
00148 {
00149 ConnectionError_t(const std::string &msg)
00150 :Error_t(CONNECTION_ERROR, msg) {}
00151 };
00152
00153
00159 struct ValueTypeError_t : public Error_t
00160 {
00161 ValueTypeError_t(const std::string &msg)
00162 :Error_t(VALUE_TYPE_ERROR, msg) {}
00163 };
00164
00165
00171 struct ClientUsageError_t : public Error_t
00172 {
00173 ClientUsageError_t(const std::string &msg)
00174 :Error_t(CLIENT_USAGE_ERROR, msg) {}
00175 };
00176
00177
00178 inline std::string strError(const char *msg, int errNo=0) {
00179 std::ostringstream errMsg;
00180 errMsg << msg
00181 << ": "
00182 << (errNo == 0 ? strerror(errno) : strerror(errNo));
00183 return errMsg.str();
00184 }
00185
00186 }
00187
00188 #endif
00189