00001
00011 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00012 #pragma once
00013 #endif
00014 #ifndef COMMON_ERROR_H_
00015 #define COMMON_ERROR_H_
00016
00017 typedef long HRESULT;
00018 #ifdef WIN32
00019 #include <windows.h>
00020 #endif
00021 #ifdef USE_DIRECTX
00022 struct ID3DXBuffer;
00023 #endif
00024
00025 namespace common
00026 {
00027
00032
00034 class Error
00035 {
00036 private:
00037 std::vector<tstring> m_Msgs;
00038
00039 protected:
00041 Error() { }
00042
00043 public:
00045
00047 void Push(const tstring &msg, const tstring &file = _T(""), int line = 0);
00049
00051 void GetMessage_(tstring *Msg, const tstring &Indent = _T(""), const tstring &EOL = EOL) const;
00052
00054 Error(const tstring &msg, const tstring &file = _T(""), int line = 0)
00055 {
00056 Push(msg, file, line);
00057 }
00058 };
00059
00061 class ErrnoError : public Error
00062 {
00063 public:
00065 ErrnoError(int err_code, const tstring &msg, const tstring &file = _T(""), int line = 0);
00067 ErrnoError(const tstring &msg, const tstring &file = _T(""), int line = 0);
00068 };
00069
00070 #ifdef USE_SDL
00072 class SDLError : public Error
00073 {
00074 public:
00075 SDLError(const tstring &msg, const tstring &file = _T(""), int line = 0);
00076 };
00077 #endif
00078
00079 #ifdef USE_OPENGL
00081 class OpenGLError : public Error
00082 {
00083 public:
00084 OpenGLError(const tstring &msg, const tstring &file = _T(""), int line = 0);
00085 };
00086 #endif
00087
00088 #ifdef USE_FMOD
00090 class FmodError : public Error
00091 {
00092 private:
00095 void CodeToMessage(FMOD_RESULT code, tstring *Enum, tstring *Message);
00096
00097 public:
00098 FmodError(FMOD_RESULT code, const tstring &msg, const tstring &file = _T(""), int line = 0);
00099 };
00100 #endif
00101
00102 #ifdef WIN32
00104 class Win32Error : public Error
00105 {
00106 public:
00107 Win32Error(const tstring &msg = _T(""), const tstring &file = _T(""), int line = 0);
00108 };
00109 #endif
00110
00111 #ifdef USE_DIRECTX
00113 class DirectXError : public Error
00114 {
00115 public:
00116 DirectXError(HRESULT hr, const tstring &Msg = _T(""), const tstring &file = _T(""), int Line = 0);
00118
00119 DirectXError(HRESULT hr, ID3DXBuffer *Buf, const tstring &Msg = _T(""), const tstring &file = _T(""), int Line = 0);
00120 };
00121 #endif
00122
00123 #ifdef USE_WINSOCK
00125 class WinSockError : public Error
00126 {
00127 private:
00128 void CodeToStr(int Code, tstring *Name, tstring *Message);
00129
00130 public:
00132 int WinSockError(int Code, const tstring &Msg = "", const tstring &file = _T(""), int Line = 0);
00134 int WinSockError(const tstring &Msg = "", const tstring &file = _T(""), int Line = 0);
00135 };
00136 #endif
00137
00138 #ifdef USE_DEVIL
00140 class DevILError : public Error
00141 {
00142 public:
00143 DevILError(const tstring &Msg = "", const tstring &file = _T(""), int a_Line = 0);
00144 };
00145 #endif
00146
00147 #ifdef USE_AVI_FILE
00149 class AVIFileError : public Error
00150 {
00151 public:
00152 AVIFileError(HRESULT hr, const tstring &Msg = "", const tstring &file = _T(""), int a_Line = 0);
00153 };
00154 #endif
00155
00157
00158
00159 }
00160
00163
00165 #define ERR_ADD_FUNC(exception) { (exception).Push(__TFUNCSIG__, __TFILE__, __LINE__); }
00166 #define ERR_TRY { try {
00167 #define ERR_CATCH(msg) } catch(Error &e) { e.Push((msg), __TFILE__, __LINE__); throw; } }
00168 #define ERR_CATCH_FUNC } catch(Error &e) { ERR_ADD_FUNC(e); throw; } }
00169
00170 #define ERR_GUARD_BOOL(Expr) { if ((Expr) == false) throw Error(_T(#Expr), __TFILE__, __LINE__); }
00171 #define ERR_GUARD_DIRECTX(Expr) { HRESULT hr; if (FAILED(hr = (Expr))) throw DirectXError(hr, _T(#Expr), __TFILE__, __LINE__); }
00172
00173 #ifdef _DEBUG
00174 #define ERR_GUARD_BOOL_D(Expr) ERR_GUARD_BOOL(Expr)
00175 #define ERR_GUARD_DIRECTX_D(Expr) ERR_GUARD_DIRECTX(Expr)
00176 #else
00177 #define ERR_GUARD_BOOL_D(Expr) (Expr);
00178 #define ERR_GUARD_DIRECTX_D(Expr) (Expr);
00179 #endif
00180
00182
00183
00185
00188 template <typename T>
00189 inline void MustStrToSth(T *Sth, const tstring &Str)
00190 {
00191 if (!StrToSth<T>(Sth, Str))
00192 throw common::Error(_T("String conversion error: ") + Str);
00193 }
00194
00195 #endif