GME
13
|
00001 #ifndef MGA_COMMONERROR_H 00002 #define MGA_COMMONERROR_H 00003 00004 #include <exception> 00005 #include <comdef.h> 00006 00007 // --------------------------- ASSERT and VERIFY 00008 00009 #if !defined(ASSERT) && defined(ATLASSERT) 00010 #define ASSERT ATLASSERT 00011 #endif 00012 00013 // --------------------------- hresult_exception 00014 00015 class hresult_exception : public std::exception 00016 { 00017 public: 00018 hresult_exception() throw(); 00019 hresult_exception(const hresult_exception &e) throw(); 00020 hresult_exception(HRESULT hr) throw(); 00021 hresult_exception &operator=(const hresult_exception &e) throw(); 00022 hresult_exception &operator=(HRESULT hr) throw(); 00023 ~hresult_exception() throw(); 00024 virtual const char *what() const throw(); 00025 00026 public: 00027 HRESULT hr; 00028 }; 00029 00030 // --------------------------- Exceptions and COM 00031 00032 #define NOTHROW throw() 00033 00034 #define COMTHROW(FUNC) \ 00035 do { \ 00036 HRESULT _hr = (FUNC); \ 00037 if( FAILED(_hr) ) { \ 00038 throw hresult_exception(_hr); \ 00039 } \ 00040 } while(false) 00041 00042 #define VERIFYTHROW(FUNC) \ 00043 do { \ 00044 if( !(bool)(FUNC) ) { \ 00045 throw hresult_exception(E_VERIFY); \ 00046 } \ 00047 } while(false) 00048 00049 #define COMVERIFY(FUNC) \ 00050 VERIFY(SUCCEEDED(FUNC)) 00051 00052 #define HR_THROW(_hr) \ 00053 do { \ 00054 throw hresult_exception(_hr); \ 00055 } while(false) 00056 00057 #define COMTRY try 00058 00059 #ifdef __AFX_H__ 00060 #define CATCH_CMEMORY_EXCEPTION(CLEANUP) \ 00061 catch (CMemoryException* e) \ 00062 { \ 00063 try { CLEANUP; } catch (const std::bad_alloc& ) { } \ 00064 e->Delete(); \ 00065 SetStandardOrGMEErrorInfo(E_OUTOFMEMORY); \ 00066 return E_OUTOFMEMORY; \ 00067 } 00068 #else 00069 #define CATCH_CMEMORY_EXCEPTION(CLEANUP) 00070 #endif 00071 00072 00073 #define COMCATCH(CLEANUP) \ 00074 catch(hresult_exception &e) \ 00075 { \ 00076 ASSERT( FAILED(e.hr) ); \ 00077 { CLEANUP; } \ 00078 SetStandardOrGMEErrorInfo(e.hr); \ 00079 return e.hr; \ 00080 } \ 00081 catch(_com_error &e) \ 00082 { \ 00083 { CLEANUP; } \ 00084 if (e.Description() != _bstr_t()) \ 00085 SetErrorInfo(e.Description()); \ 00086 else \ 00087 SetStandardOrGMEErrorInfo(e.Error()); \ 00088 return e.Error(); \ 00089 } \ 00090 catch (const std::bad_alloc& ) \ 00091 { \ 00092 try { CLEANUP; } catch (const std::bad_alloc& ) { } \ 00093 SetStandardOrGMEErrorInfo(E_OUTOFMEMORY); \ 00094 return E_OUTOFMEMORY; \ 00095 } \ 00096 CATCH_CMEMORY_EXCEPTION(CLEANUP) \ 00097 return S_OK; 00098 00099 #define COMRETURN(HR) \ 00100 { \ 00101 HRESULT _hr = HR; \ 00102 if( FAILED(_hr) ) \ 00103 SetErrorInfo(_hr); \ 00104 return _hr; \ 00105 } 00106 00107 inline bool CheckOut_IsBound(BSTR b) { return b != NULL; } 00108 inline bool CheckOut_IsBound(const VARIANT &v) { return !(v.vt == VT_EMPTY || v.vt == VT_NULL); } 00109 inline bool CheckOut_IsBound(const IUnknown *p) { return p != NULL; } 00110 inline bool CheckOut_IsBound(const int) { return false; } 00111 inline bool CheckOut_IsBound(const short) { return false; } 00112 inline bool CheckOut_IsBound(const ULONG) { return false; } 00113 inline bool CheckOut_IsBound(const SAFEARRAY *p) { return p != NULL; } 00114 00115 #define CHECK_IN(PTR) \ 00116 { \ 00117 if( PTR == NULL ) \ 00118 COMRETURN(E_INVALIDARG) \ 00119 } 00120 00121 #define CHECK_OUT(PTR) \ 00122 { \ 00123 if( PTR == NULL ) \ 00124 COMRETURN(E_POINTER) \ 00125 else if( CheckOut_IsBound(*PTR) ) \ 00126 COMRETURN(E_OUT_NOT_EMPTY) \ 00127 } 00128 00129 #define CHECK_INOUT(PTR) \ 00130 { \ 00131 if( PTR == NULL ) \ 00132 COMRETURN(E_INVALIDARG) \ 00133 } 00134 00135 // --------------------------- Common Error Codes 00136 00137 00138 void throw_com_error(HRESULT hr, LPCOLESTR desc); 00139 void throw_last_com_error(HRESULT hr); 00140 void SetErrorInfo(LPCOLESTR desc) NOTHROW; 00141 void SetErrorInfo(HRESULT hr, LPOLESTR desc2 = NULL) NOTHROW; 00142 bool GetErrorInfo(BSTR *p) NOTHROW; 00143 void GetErrorInfo(HRESULT hr, BSTR *p) NOTHROW; 00144 static void SetStandardOrGMEErrorInfo(HRESULT hr) NOTHROW { 00145 _bstr_t error; 00146 GetErrorInfo(hr, error.GetAddress()); 00147 if (static_cast<LPOLESTR>(error)) 00148 SetErrorInfo(static_cast<LPOLESTR>(error)); 00149 } 00150 00151 // One or more arguments are invalid 00152 //***** E_INVALIDARG 00153 00154 // Not enough storage is available to complete this operation 00155 //***** E_OUTOFMEMORY 00156 00157 // no implementation yet 00158 //***** E_NOTIMPL 00159 00160 // Class is not properly used 00161 #define E_INVALID_USAGE _HRESULT_TYPEDEF_(0x80731001) 00162 00163 // Unknown exception 00164 #define E_EXCEPTION _HRESULT_TYPEDEF_(0x80731002) 00165 00166 // conversion failed 00167 #define E_CONVERSION _HRESULT_TYPEDEF_(0x80731003) 00168 00169 // requested != count in GetAll 00170 #define E_GETALL _HRESULT_TYPEDEF_(0x80731004) 00171 00172 // output parameter is not empty 00173 #define E_OUT_NOT_EMPTY _HRESULT_TYPEDEF_(0x80731005) 00174 00175 // the passed interface is not from this module 00176 #define E_SAMEPROJECT _HRESULT_TYPEDEF_(0x80731006) 00177 00178 // object was not found 00179 #define E_NOTFOUND _HRESULT_TYPEDEF_(0x80731007) 00180 00181 // file open error 00182 #define E_FILEOPEN _HRESULT_TYPEDEF_(0x80731008) 00183 00184 // VERIFY has failed 00185 #define E_VERIFY _HRESULT_TYPEDEF_(0x80731009) 00186 00187 // COMTHROW test exception 00188 #define E_COMTHROW_TEST _HRESULT_TYPEDEF_(0x8073100A) 00189 00190 // the description table is in CommonError.cpp 00191 #define E_COMMON_FIRST E_INVALID_USAGE 00192 #define E_COMMON_LAST E_COMTHROW_TEST 00193 00194 // --------------------------- Core Error Codes 00195 00196 // Could not gain lock because an item is already locked 00197 #define E_LOCK_VIOLATION _HRESULT_TYPEDEF_(0x80732001) 00198 00199 // The lock value in the database is not valid 00200 #define E_INVALID_LOCK_VALUE _HRESULT_TYPEDEF_(0x80732002) 00201 00202 // Attribute not found 00203 #define E_ATTRID _HRESULT_TYPEDEF_(0x80732003) 00204 00205 // Meta object not found 00206 #define E_METAID _HRESULT_TYPEDEF_(0x80732004) 00207 00208 // meta project is invalid 00209 #define E_METAPROJECT _HRESULT_TYPEDEF_(0x80732005) 00210 00211 // invalid response from the repository 00212 #define E_REPOSITORY _HRESULT_TYPEDEF_(0x80732006) 00213 00214 // project - metaproject mismatch 00215 #define E_PROJECT_MISMATCH _HRESULT_TYPEDEF_(0x80732007) 00216 00217 // object has been deleted, zombie 00218 #define E_ZOMBIE _HRESULT_TYPEDEF_(0x80732008) 00219 00220 // invalid valtype 00221 #define E_VALTYPE _HRESULT_TYPEDEF_(0x80732009) 00222 00223 // no active transaction 00224 #define E_TRANSACTION _HRESULT_TYPEDEF_(0x8073200A) 00225 00226 // the object already exists 00227 #define E_OBJECTEXISTS _HRESULT_TYPEDEF_(0x8073200B) 00228 00229 // no territory selected 00230 #define E_TERRITORY _HRESULT_TYPEDEF_(0x8073200C) 00231 00232 // not locked 00233 #define E_NOTLOCKED _HRESULT_TYPEDEF_(0x8073200D) 00234 00235 // invalid data in repository 00236 #define E_REPOSITORY_DATA _HRESULT_TYPEDEF_(0x8073200E) 00237 00238 // cannot delete object because of nonempty collection 00239 #define E_NONEMPTY_COLL _HRESULT_TYPEDEF_(0x8073200F) 00240 00241 // cannot resolve the connection string 00242 #define E_UNKNOWN_STORAGE _HRESULT_TYPEDEF_(0x80732010) 00243 00244 // binary file storage is invalid 00245 #define E_BINFILE _HRESULT_TYPEDEF_(0x80732011) 00246 00247 // missing name 00248 #define E_NAMEMISSING _HRESULT_TYPEDEF_(0x80732012) 00249 00250 // the description table is in CommonError.cpp 00251 #define E_CORE_FIRST E_LOCK_VIOLATION 00252 #define E_CORE_LAST E_NAMEMISSING 00253 00254 // --------------------------- Meta Error Codes 00255 00256 // invalid attval_type 00257 #define E_ATTVALTYPE _HRESULT_TYPEDEF_(0x80733001) 00258 00259 // metaproject is not open 00260 #define E_META_NOTOPEN _HRESULT_TYPEDEF_(0x80733002) 00261 00262 // invalid path 00263 #define E_INVALID_PATH _HRESULT_TYPEDEF_(0x80733003) 00264 00265 // invalid metaref 00266 #define E_METAREF _HRESULT_TYPEDEF_(0x80733004) 00267 00268 // the description table is in CommonError.cpp 00269 #define E_META_FIRST E_ATTVALTYPE 00270 #define E_META_LAST E_METAREF 00271 00272 // --------------------------- Parser Error Codes 00273 00274 // XML parser exception, WE SET THE DESCRIPTION MANUALLY 00275 #define E_XMLPARSER _HRESULT_TYPEDEF_(0x80734001) 00276 00277 // Invalid DTD file 00278 #define E_INVALID_DTD _HRESULT_TYPEDEF_(0x80734002) 00279 00280 // Invalid GUID 00281 #define E_INVALID_GUID _HRESULT_TYPEDEF_(0x80734003) 00282 00283 // Invalid XML filename 00284 #define E_INVALID_FILENAME _HRESULT_TYPEDEF_(0x80734004) 00285 00286 // Invalid MGA object 00287 #define E_INVALID_MGA _HRESULT_TYPEDEF_(0x80734005) 00288 00289 // Invalid META object 00290 #define E_INVALID_META _HRESULT_TYPEDEF_(0x80734006) 00291 00292 // Too many passes while parsing the XML file 00293 #define E_TOOMANYPASSES _HRESULT_TYPEDEF_(0x80734007) 00294 00295 // Invalid long value 00296 #define E_INVALID_XML_LONG _HRESULT_TYPEDEF_(0x80734008) 00297 00298 // the description table is in CommonError.cpp 00299 #define E_PARSER_FIRST E_INVALID_DTD 00300 #define E_PARSER_LAST E_INVALID_XML_LONG 00301 00302 // XSLT transformation error codes 00303 #define E_XSLT_XERCES_INIT _HRESULT_TYPEDEF_(0x80734009) 00304 #define E_XSLT_COMPILE_ERROR _HRESULT_TYPEDEF_(0x8073400A) 00305 #define E_XSLT_TRANSF_ERROR _HRESULT_TYPEDEF_(0x8073400B) 00306 #define E_XSLT_ERROR _HRESULT_TYPEDEF_(0x8073400C) 00307 #define E_XSLTFILESEL_USER_ABORTED _HRESULT_TYPEDEF_(0x8073400D) 00308 00309 #endif//MGA_COMMONERROR_H