abexception.cpp

来自「miXo is a buzz machine (www.buzzmachines」· C++ 代码 · 共 55 行

CPP
55
字号
#include "stdafx.h"
#include <sstream>
#include "AbException.h"
CAbException::CAbException() throw() 
: exception(),m_uError(0),m_strFile(""),m_uLine(0l),m_bSystem(true)  
{
#ifdef _DEBUG
	m_uError=::GetLastError();
	m_bSystem=true;
	DebugOutput();
#endif
}
CAbException::CAbException(unsigned u) throw() 
: exception(),m_uError(u),m_strFile(""),m_uLine(0l),m_bSystem(true) 
{
#ifdef _DEBUG
	DebugOutput();
#endif
}
CAbException::CAbException(unsigned u,const char *f,unsigned l,bool bSystem)  throw() 
: exception(),m_uError(u),m_strFile(f),m_uLine(l),m_bSystem(bSystem) 
{
#ifdef _DEBUG
	DebugOutput();
#endif
}
void CAbException::DebugOutput()
{
#ifdef _DEBUG
	string str=GetMessage();
	::OutputDebugString(str.c_str());
#endif
}
string CAbException::GetMessage() const
{
	string strTheMsg;
	if(m_bSystem) {
		void far *lpMsgBuf;		
		::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
			NULL,m_uError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
			(LPSTR)&lpMsgBuf,0,NULL);
		strTheMsg=reinterpret_cast<char far*>(lpMsgBuf);
		LocalFree( lpMsgBuf );
	}else{
		switch(m_uError) {
		case err_ResourceLeak:
			strTheMsg="Resource Leak";
			break;
		}
	}
	stringstream stmTemp;
	stmTemp << strTheMsg << " in File:" << m_strFile << ", Line:" << m_uLine << ends;
	strTheMsg=stmTemp.str();
	return strTheMsg;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?