- Main Page
- Classes
- Files

- File List
- File Members

# C:/Users/Public/AGS Final Folder/BFLETCHER D4010283/Source/Game/Source/GameException.cpp

Go to the documentation of this file.

    00001 #include "GameException.h"
    00002
    00003 #include "SDL.h"
    00004
    00005 std::vector<GameException> GameException::m_svLog;
    00006 unsigned int GameException::m_sTotalErrors = 0;
    00007
    00008 GameException::GameException(const eErrorSeverity &severity, const std::string &str)
    00009 : m_str(str), m_severity(severity)
    00010 {
    00011         m_time = SDL_GetTicks();
    00012         m_sTotalErrors++;
    00013         m_svLog.push_back(*this);
    00014 }
    00015
    00016 GameException::GameException(const eErrorSeverity &severity, const char *str, ...)
    00017 : m_severity(severity)
    00018 {
    00019         char* pBuf = 0;
    00020
    00021         va_list args;
    00022         va_start(args,str);
    00023
    00024 #ifdef _WIN32
    00025         size_t len = _vscprintf( str, args ) + 1;
    00026         pBuf = new char[len];
    00027         vsprintf_s( pBuf, len, str, args );
    00028 #else
    00029         pBuf = new char[2048];
    00030         vsprintf(pBuf,str,args);
    00031 #endif
    00032
    00033
    00034         m_str = std::string(pBuf);
    00035         delete[] pBuf;
    00036
    00037         m_time = SDL_GetTicks();
    00038         m_sTotalErrors++;
    00039         m_svLog.push_back(*this);
    00040 }
    00041
    00042 void GameException::Output(std::ostream &stream)
    00043 {
    00044         stream << "Description : " << GetDescription() << std::endl;
    00045         stream << "Severity        : " << GetSeverity() << std::endl;
    00046         stream << "Time        : " << GetTime() << std::endl;
    00047 }
    00048
    00049 void GameException::OutputLog(std::ostream &stream)
    00050 {
    00051         stream << "Exception Log :" << std::endl << std::endl;
    00052
    00053         for(size_t i = 0; i < m_svLog.size(); i++)
    00054         {
    00055                 stream << std::endl;
    00056                 stream << "Error No.   : " << i << std::endl;
    00057                 stream << "Description : " << m_svLog[i].GetDescription() << std::endl;
    00058                 stream << "Severity        : " << m_svLog[i].GetSeverity() << std::endl;
    00059                 stream << "Time        : " << m_svLog[i].GetTime() << std::endl;
    00060         }
    00061 }
    00062
    00063 std::string GameException::ConvertSeverityToString(const eErrorSeverity &severity)
    00064 {
    00065         switch(severity)
    00066         {
    00067                 case eMinorError:
    00068                         return std::string("Minor");
    00069                 case eMajorError:
    00070                         return std::string("Major");
    00071                 case eFatalError:
    00072                         return std::string("Fatal");
    00073         }
    00074
    00075         return std::string("Unrecognised Severity");
    00076 }