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
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #if !defined(EXCEPTION_HPP)
00062 #define EXCEPTION_HPP
00063
00064 #include <xercesc/util/XMemory.hpp>
00065 #include <xercesc/util/XMLExceptMsgs.hpp>
00066 #include <xercesc/util/XMLUni.hpp>
00067 #include <xercesc/framework/XMLErrorReporter.hpp>
00068
00069 XERCES_CPP_NAMESPACE_BEGIN
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 class XMLException : public XMemory
00081 {
00082 public:
00083
00084
00085
00086 virtual ~XMLException();
00087
00088
00089
00090
00091
00092 virtual const XMLCh* getType() const = 0;
00093
00094
00095
00096
00097
00098 XMLExcepts::Codes getCode() const;
00099 const XMLCh* getMessage() const;
00100 const char* getSrcFile() const;
00101 unsigned int getSrcLine() const;
00102 XMLErrorReporter::ErrTypes getErrorType() const;
00103
00104
00105
00106
00107
00108 void setPosition(const char* const file, const unsigned int line);
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 XMLException();
00121 XMLException(const char* const srcFile, const unsigned int srcLine);
00122 XMLException(const XMLException& toCopy);
00123 XMLException& operator=(const XMLException& toAssign);
00124
00125
00126
00127
00128 static void reinitMsgMutex();
00129
00130 static void reinitMsgLoader();
00131
00132 protected :
00133
00134
00135
00136 void loadExceptText
00137 (
00138 const XMLExcepts::Codes toLoad
00139 );
00140 void loadExceptText
00141 (
00142 const XMLExcepts::Codes toLoad
00143 , const XMLCh* const text1
00144 , const XMLCh* const text2 = 0
00145 , const XMLCh* const text3 = 0
00146 , const XMLCh* const text4 = 0
00147 );
00148 void loadExceptText
00149 (
00150 const XMLExcepts::Codes toLoad
00151 , const char* const text1
00152 , const char* const text2 = 0
00153 , const char* const text3 = 0
00154 , const char* const text4 = 0
00155 );
00156
00157
00158 private :
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 XMLExcepts::Codes fCode;
00174 char* fSrcFile;
00175 unsigned int fSrcLine;
00176 XMLCh* fMsg;
00177 };
00178
00179
00180
00181
00182 inline XMLExcepts::Codes XMLException::getCode() const
00183 {
00184 return fCode;
00185 }
00186
00187 inline const XMLCh* XMLException::getMessage() const
00188 {
00189 return fMsg;
00190 }
00191
00192 inline const char* XMLException::getSrcFile() const
00193 {
00194 if (!fSrcFile)
00195 return "";
00196 return fSrcFile;
00197 }
00198
00199 inline unsigned int XMLException::getSrcLine() const
00200 {
00201 return fSrcLine;
00202 }
00203
00204 inline XMLErrorReporter::ErrTypes XMLException::getErrorType() const
00205 {
00206 if ((fCode >= XMLExcepts::W_LowBounds) && (fCode <= XMLExcepts::W_HighBounds))
00207 return XMLErrorReporter::ErrType_Warning;
00208 else if ((fCode >= XMLExcepts::F_LowBounds) && (fCode <= XMLExcepts::F_HighBounds))
00209 return XMLErrorReporter::ErrType_Fatal;
00210 else if ((fCode >= XMLExcepts::E_LowBounds) && (fCode <= XMLExcepts::E_HighBounds))
00211 return XMLErrorReporter::ErrType_Error;
00212 return XMLErrorReporter::ErrTypes_Unknown;
00213 }
00214
00215
00216
00217
00218
00219
00220 #define MakeXMLException(theType, expKeyword) \
00221 class expKeyword theType : public XMLException \
00222 { \
00223 public: \
00224 \
00225 theType(const char* const srcFile \
00226 , const unsigned int srcLine \
00227 , const XMLExcepts::Codes toThrow) : \
00228 XMLException(srcFile, srcLine) \
00229 { \
00230 loadExceptText(toThrow); \
00231 } \
00232 \
00233 theType(const theType& toCopy) : \
00234 \
00235 XMLException(toCopy) \
00236 { \
00237 } \
00238 \
00239 theType(const char* const srcFile \
00240 , const unsigned int srcLine \
00241 , const XMLExcepts::Codes toThrow \
00242 , const XMLCh* const text1 \
00243 , const XMLCh* const text2 = 0 \
00244 , const XMLCh* const text3 = 0 \
00245 , const XMLCh* const text4 = 0) : \
00246 XMLException(srcFile, srcLine) \
00247 { \
00248 loadExceptText(toThrow, text1, text2, text3, text4); \
00249 } \
00250 \
00251 theType(const char* const srcFile \
00252 , const unsigned int srcLine \
00253 , const XMLExcepts::Codes toThrow \
00254 , const char* const text1 \
00255 , const char* const text2 = 0 \
00256 , const char* const text3 = 0 \
00257 , const char* const text4 = 0) : \
00258 XMLException(srcFile, srcLine) \
00259 { \
00260 loadExceptText(toThrow, text1, text2, text3, text4); \
00261 } \
00262 \
00263 virtual ~theType() {} \
00264 \
00265 theType& operator=(const theType& toAssign) \
00266 { \
00267 XMLException::operator=(toAssign); \
00268 return *this; \
00269 } \
00270 \
00271 virtual XMLException* duplicate() const \
00272 { \
00273 return new theType(*this); \
00274 } \
00275 \
00276 virtual const XMLCh* getType() const \
00277 { \
00278 return XMLUni::fg##theType##_Name; \
00279 } \
00280 \
00281 private : \
00282 theType(); \
00283 };
00284
00285
00286
00287
00288
00289
00290
00291
00292 #define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
00293
00294 #define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
00295
00296 #define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
00297
00298 #define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
00299
00300 #define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
00301
00302 XERCES_CPP_NAMESPACE_END
00303
00304 #endif