00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(XERCESC_INCLUDE_GUARD_XMLEXCEPTION_HPP)
00023 #define XERCESC_INCLUDE_GUARD_XMLEXCEPTION_HPP
00024
00025 #include <xercesc/util/XercesDefs.hpp>
00026 #include <xercesc/util/XMemory.hpp>
00027 #include <xercesc/util/XMLExceptMsgs.hpp>
00028 #include <xercesc/util/XMLUni.hpp>
00029 #include <xercesc/framework/XMLErrorReporter.hpp>
00030
00031 XERCES_CPP_NAMESPACE_BEGIN
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 class XMLUTIL_EXPORT XMLException : public XMemory
00043 {
00044 public:
00045
00046
00047
00048 virtual ~XMLException();
00049
00050
00051
00052
00053
00054 virtual const XMLCh* getType() const = 0;
00055
00056
00057
00058
00059
00060 XMLExcepts::Codes getCode() const;
00061 const XMLCh* getMessage() const;
00062 const char* getSrcFile() const;
00063 XMLFileLoc getSrcLine() const;
00064 XMLErrorReporter::ErrTypes getErrorType() const;
00065
00066
00067
00068
00069
00070 void setPosition(const char* const file, const XMLFileLoc line);
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 XMLException();
00083 XMLException(const char* const srcFile, const XMLFileLoc srcLine, MemoryManager* const memoryManager = 0);
00084 XMLException(const XMLException& toCopy);
00085 XMLException& operator=(const XMLException& toAssign);
00086
00087 protected :
00088
00089
00090
00091 void loadExceptText
00092 (
00093 const XMLExcepts::Codes toLoad
00094 );
00095 void loadExceptText
00096 (
00097 const XMLExcepts::Codes toLoad
00098 , const XMLCh* const text1
00099 , const XMLCh* const text2 = 0
00100 , const XMLCh* const text3 = 0
00101 , const XMLCh* const text4 = 0
00102 );
00103 void loadExceptText
00104 (
00105 const XMLExcepts::Codes toLoad
00106 , const char* const text1
00107 , const char* const text2 = 0
00108 , const char* const text3 = 0
00109 , const char* const text4 = 0
00110 );
00111
00112
00113 private :
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 XMLExcepts::Codes fCode;
00129 char* fSrcFile;
00130 XMLFileLoc fSrcLine;
00131 XMLCh* fMsg;
00132
00133 protected:
00134 MemoryManager* fMemoryManager;
00135 };
00136
00137
00138
00139
00140 inline XMLExcepts::Codes XMLException::getCode() const
00141 {
00142 return fCode;
00143 }
00144
00145 inline const XMLCh* XMLException::getMessage() const
00146 {
00147 return fMsg;
00148 }
00149
00150 inline const char* XMLException::getSrcFile() const
00151 {
00152 if (!fSrcFile)
00153 return "";
00154 return fSrcFile;
00155 }
00156
00157 inline XMLFileLoc XMLException::getSrcLine() const
00158 {
00159 return fSrcLine;
00160 }
00161
00162 inline XMLErrorReporter::ErrTypes XMLException::getErrorType() const
00163 {
00164 if ((fCode >= XMLExcepts::W_LowBounds) && (fCode <= XMLExcepts::W_HighBounds))
00165 return XMLErrorReporter::ErrType_Warning;
00166 else if ((fCode >= XMLExcepts::F_LowBounds) && (fCode <= XMLExcepts::F_HighBounds))
00167 return XMLErrorReporter::ErrType_Fatal;
00168 else if ((fCode >= XMLExcepts::E_LowBounds) && (fCode <= XMLExcepts::E_HighBounds))
00169 return XMLErrorReporter::ErrType_Error;
00170 return XMLErrorReporter::ErrTypes_Unknown;
00171 }
00172
00173
00174
00175
00176
00177
00178 #define MakeXMLException(theType, expKeyword) \
00179 class expKeyword theType : public XMLException \
00180 { \
00181 public: \
00182 \
00183 theType(const char* const srcFile \
00184 , const XMLFileLoc srcLine \
00185 , const XMLExcepts::Codes toThrow \
00186 , MemoryManager* memoryManager = 0) : \
00187 XMLException(srcFile, srcLine, memoryManager) \
00188 { \
00189 loadExceptText(toThrow); \
00190 } \
00191 \
00192 theType(const theType& toCopy) : \
00193 \
00194 XMLException(toCopy) \
00195 { \
00196 } \
00197 \
00198 theType(const char* const srcFile \
00199 , const XMLFileLoc srcLine \
00200 , const XMLExcepts::Codes toThrow \
00201 , const XMLCh* const text1 \
00202 , const XMLCh* const text2 = 0 \
00203 , const XMLCh* const text3 = 0 \
00204 , const XMLCh* const text4 = 0 \
00205 , MemoryManager* memoryManager = 0) : \
00206 XMLException(srcFile, srcLine, memoryManager) \
00207 { \
00208 loadExceptText(toThrow, text1, text2, text3, text4); \
00209 } \
00210 \
00211 theType(const char* const srcFile \
00212 , const XMLFileLoc srcLine \
00213 , const XMLExcepts::Codes toThrow \
00214 , const char* const text1 \
00215 , const char* const text2 = 0 \
00216 , const char* const text3 = 0 \
00217 , const char* const text4 = 0 \
00218 , MemoryManager* memoryManager = 0) : \
00219 XMLException(srcFile, srcLine, memoryManager) \
00220 { \
00221 loadExceptText(toThrow, text1, text2, text3, text4); \
00222 } \
00223 \
00224 virtual ~theType() {} \
00225 \
00226 theType& operator=(const theType& toAssign) \
00227 { \
00228 XMLException::operator=(toAssign); \
00229 return *this; \
00230 } \
00231 \
00232 virtual XMLException* duplicate() const \
00233 { \
00234 return new (fMemoryManager) theType(*this); \
00235 } \
00236 \
00237 virtual const XMLCh* getType() const \
00238 { \
00239 return XMLUni::fg##theType##_Name; \
00240 } \
00241 \
00242 private : \
00243 theType(); \
00244 };
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 #define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
00255
00256 #define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
00257
00258 #define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
00259
00260 #define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
00261
00262 #define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
00263
00264 #define ThrowXMLwithMemMgr(type,code,memMgr) throw type(__FILE__, __LINE__, code, memMgr)
00265
00266 #define ThrowXMLwithMemMgr1(type,code,p1,memMgr) throw type(__FILE__, __LINE__, code, p1, 0, 0, 0, memMgr)
00267
00268 #define ThrowXMLwithMemMgr2(type,code,p1,p2,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, 0, 0, memMgr)
00269
00270 #define ThrowXMLwithMemMgr3(type,code,p1,p2,p3,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, 0, memMgr)
00271
00272 #define ThrowXMLwithMemMgr4(type,code,p1,p2,p3,p4,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4, memMgr)
00273
00274 XERCES_CPP_NAMESPACE_END
00275
00276 #endif