00001
00036 #include <fstream>
00037
00038 class ExceptionInfo
00039 {
00040 public:
00041 const char* m_szText;
00042 const char* m_szFileName;
00043 int m_nLine;
00044
00045 ExceptionInfo()
00046 {
00047 m_szText = "Default exception message.";
00048 m_nLine = 0;
00049 m_szFileName = "";
00050 }
00051
00052 ExceptionInfo(const char* szText, const char* szFileName, int nLine)
00053 {
00054 m_szText = szText;
00055 m_szFileName = szFileName;
00056 m_nLine = nLine;
00057 }
00058
00059 ExceptionInfo(const ExceptionInfo& e)
00060 {
00061 *this = e;
00062 }
00063
00064 ExceptionInfo& operator=(const ExceptionInfo& e)
00065 {
00066 m_szText = e.m_szText;
00067 m_szFileName = e.m_szFileName;
00068 m_nLine = e.m_nLine;
00069
00070 return *this;
00071 }
00072
00073 void Print(ostream& os = cerr)
00074 {
00075 os << "\n\nException occurred at line " << m_nLine << " in " << m_szFileName
00076 << ": " << m_szText << endl << endl;
00077 }
00078 };
00079
00080
00081 #define THROW_EXCEPTION(A) throw ExceptionInfo(A, __FILE__, __LINE__)