00001
00002
00003
00004
00005
00006
00007
00009
00010 #ifndef __wx_exception_h__
00011 #define __wx_exception_h__
00012
00013 #include <wx/wxprec.h>
00014 #ifndef WX_PRECOMP
00015 #include "wx/wx.h"
00016 #endif
00017
00018 namespace wx
00019 {
00020
00021 #ifdef _MSC_VER
00022
00023 #define WorkaroundVa_start(ap,v) \
00024 { \
00025 int var= _INTSIZEOF(v); \
00026 __asm lea eax,v \
00027 __asm add eax,var \
00028 __asm mov ap,eax \
00029 }
00030 #endif // def _MSC_VER
00031
00032 class Exception
00033 {
00034
00035
00036
00037 public:
00038 Exception() :
00039 m_sError(wxT("")),
00040 m_szFile(NULL),
00041 m_nLine(-1)
00042 {
00043 }
00044
00045 Exception(const Exception& e)
00046 {
00047 m_sError = e.m_sError;
00048 m_szFile = e.m_szFile;
00049 m_nLine = e.m_nLine;
00050 }
00051
00052 Exception(const wxString& sError, ...) :
00053 m_szFile(NULL),
00054 m_nLine(-1)
00055 {
00056 va_list argptr;
00057 #ifdef _MSC_VER
00058 WorkaroundVa_start(argptr, sError);
00059 #else
00060 va_start(argptr, sError);
00061 #endif // def _MSC_VER
00062 m_sError.PrintfV(sError, argptr);
00063 va_end(argptr);
00064 }
00065
00066 Exception(const char * szFile, int nLine, const wxString& sError, ...) :
00067 m_szFile(szFile),
00068 m_nLine(nLine)
00069 {
00070 va_list argptr;
00071 #ifdef _MSC_VER
00072 WorkaroundVa_start(argptr, sError);
00073 #else
00074 va_start(argptr, sError);
00075 #endif // def _MSC_VER
00076 m_sError.PrintfV(sError, argptr);
00077 va_end(argptr);
00078 }
00079
00080 Exception(const Exception& e, const wxString& sError, ...)
00081 {
00082 va_list argptr;
00083 #ifdef _MSC_VER
00084 WorkaroundVa_start(argptr, sError);
00085 #else
00086 va_start(argptr, sError);
00087 #endif // def _MSC_VER
00088 m_sError.PrintfV(sError, argptr);
00089 va_end(argptr);
00090
00091 m_sError << wxT("\n") + e.GetString();
00092 }
00093
00094 virtual Exception::~Exception()
00095 {}
00096
00097 void PrintfV(const wxString& sError, va_list argptr)
00098 {
00099 m_sError.PrintfV(sError, argptr);
00100 }
00101
00102
00103 public:
00104 virtual operator wxString()
00105 { return GetString(); }
00106 virtual const char * GetFile()
00107 { return m_szFile; }
00108 virtual const int GetLine()
00109 { return m_nLine; }
00110
00111
00112 public:
00113 const wxString& GetString() const
00114 {
00115 return m_sError;
00116 }
00117
00118
00119 protected:
00120 wxString m_sError;
00121 const char * m_szFile;
00122 int m_nLine;
00123 };
00124
00125 }
00126
00127 #endif // ndef __wx_exception_h__