Clone
ixen <ixen@copyhandler.com>
committed
on 09 Jun 13
Added missing exception files created when adding unit tests (CH-60).
LoggerImprovements + 5 more
src/libchcore/TBaseException.cpp (+57)
  1 #include "stdafx.h"
  2 #include "TBaseException.h"
  3 #include <atltrace.h>
  4
  5 BEGIN_CHCORE_NAMESPACE
  6
  7 TBaseException::TBaseException(EGeneralErrors eErrorCode, const wchar_t* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction) :
  8         m_eErrorCode(eErrorCode),
  9         m_pszMsg(pszMsg),
  10         m_bDeleteMsg(false),
  11         m_pszFile(pszFile),
  12         m_stLineNumber(stLineNumber),
  13         m_pszFunction(pszFunction)
  14 {
  15         ATLTRACE(_T("*** Base Exception is being thrown:\n\tMsg: %s\n\tError code: %ld\n\tFile: %s\n\tLine number: %ld\n\tFunction: %s\n"), pszMsg, eErrorCode, pszFile, stLineNumber, pszFunction);
  16 }
  17
  18 TBaseException::TBaseException(EGeneralErrors eErrorCode, const char* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction) :
  19         m_eErrorCode(eErrorCode),
  20         m_pszMsg(NULL),
  21         m_bDeleteMsg(false),
  22         m_pszFile(pszFile),
  23         m_stLineNumber(stLineNumber),
  24         m_pszFunction(pszFunction)
  25 {
  26         ATLTRACE(_T("*** Base Exception is being thrown:\n\tMsg: %S\n\tError code: %ld\n\tFile: %s\n\tLine number: %ld\n\tFunction: %s\n"), pszMsg, eErrorCode, pszFile, stLineNumber, pszFunction);
  27         if(pszMsg)
  28         {
  29                 size_t stMsgLen = strlen(pszMsg);
  30                 m_pszMsg = new wchar_t[stMsgLen + 1];
  31                 
  32                 size_t stResult = 0;
  33                 mbstowcs_s(&stResult, const_cast<wchar_t*>(m_pszMsg), stMsgLen + 1, pszMsg, _TRUNCATE);
  34         }
  35 }
  36
  37 TBaseException::~TBaseException()
  38 {
  39         if(m_bDeleteMsg)
  40                 delete [] m_pszMsg;
  41 }
  42
  43 void TBaseException::GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const
  44 {
  45         _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %ld)"),
  46                 m_pszMsg, m_eErrorCode);
  47         pszBuffer[stMaxBuffer - 1] = _T('\0');
  48 }
  49
  50 void TBaseException::GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const
  51 {
  52         _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s\r\nError code: %ld\r\nFile: %s\r\nFunction: %s\r\nLine no: %lu"),
  53                 m_pszMsg, m_eErrorCode, m_pszFile, m_pszFunction, m_stLineNumber);
  54         pszBuffer[stMaxBuffer - 1] = _T('\0');
  55 }
  56
  57 END_CHCORE_NAMESPACE