📄 resexception.cpp
字号:
// ResException.cpp
//
// Author: Lea Hayes
// Date Created: 26/03/2006
// Date Modified: 26/03/2006
#include "Common.h"
#include "ResException.h"
using namespace std;
using namespace Resources;
// ResException - Default exceptions.
const ResException ResException::Unknown("Unknown");
const ResException ResException::UnableToOpenFile("Unable to open file");
const ResException ResException::UnableToCreate("Unable to create");
// ResException - Construction and destruction.
ResException::ResException(const ResException& src)
: m_szException(NULL)
, m_szExtraInfo(NULL)
, m_szSrcFile(NULL)
{
// Set exception text.
SetException(src.GetText());
// Set extra exception information.
SetExtraInfo(src.GetExtraInfo());
// Prepare exception with source file and line number.
SetSourceFile(src.GetSourceFile(), src.GetLineNumber());
}
ResException::ResException(LPCSTR lpszException,
LPCSTR lpszSrcFile /*=NULL*/,
DWORD dwLineNo /*=NULL*/)
: m_szException(NULL)
, m_szExtraInfo(NULL)
, m_szSrcFile(NULL)
{
// Set exception text.
SetException(lpszException);
// Prepare exception with source file and line number.
SetSourceFile(lpszSrcFile, dwLineNo);
}
ResException::~ResException()
{
// Free any string allocations.
if(m_szSrcFile != NULL)
delete[] m_szSrcFile;
if(m_szException != NULL)
delete[] m_szException;
if(m_szExtraInfo != NULL)
delete[] m_szExtraInfo;
}
// ResException - Function operator overload.
ResException ResException::operator() (LPCSTR lpszSrcFile,
DWORD dwLineNo) const
{
// Create copy of template exception.
return ResException(GetText(), lpszSrcFile, dwLineNo);
}
// ResException - Properties.
void ResException::SetString(LPSTR* lpszOut, LPCSTR lpszIn)
{
// Free current string allocation (if any).
if(*lpszOut != NULL)
{
delete[] *lpszOut;
*lpszOut = NULL;
}
// Use string specified (if any).
if(lpszIn != NULL)
{
*lpszOut = new char[strlen(lpszIn) + 1];
strcpy(*lpszOut, lpszIn);
}
}
void ResException::SetException(LPCSTR lpszException)
{
// Use exception string specified.
SetString(&m_szException, lpszException);
}
void ResException::SetExtraInfo(LPCSTR lpszExtraInfo)
{
// Use extra information string specified.
SetString(&m_szExtraInfo, lpszExtraInfo);
}
void ResException::SetSourceFile(LPCSTR lpszSrcFile,
DWORD dwLineNo)
{
// Use source file information string specified.
SetString(&m_szSrcFile, lpszSrcFile);
// Use line number specified.
m_dwLineNo = dwLineNo;
}
string ResException::ToString() const
{
// Create exception string from each of its parts.
string szReturn = "Exception \"";
szReturn += GetText();
// If additional information is available then add to string.
if(GetExtraInfo() != NULL)
{
szReturn += " : ";
szReturn += GetExtraInfo();
szReturn += "\"";
}
// If available, add additional debug details.
if(GetSourceFile() != NULL)
{
szReturn += "\n\nOccurred in \"";
szReturn += GetSourceFile();
szReturn += "\" at line no ";
// Convert line number to string.
char szLineNo[10];
itoa(GetLineNumber(), szLineNo, 10);
szReturn += szLineNo;
}
// Return this string.
return szReturn;
}
// ResException - Operator overloads.
bool ResException::operator== (const ResException& src) const
{
// If exception text is identical then return true;
// otherwise return false.
return !strcmp(GetText(), src.GetText());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -