?? exception.cpp
字號:
#include "exception.h"
#include <iostream>
using namespace std;
namespace mylib{
#if defined(WIN32)
char g_errstring[1024];
const char* PrintError(DWORD errnumber)
{
memset(g_errstring,0,1024);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
errnumber,
LANG_NEUTRAL,
g_errstring,
1024,
NULL );
return g_errstring;
}
const char* STRERROR_WIN(int type)
{
switch (type)
{
case WIN32_SYS:
return PrintError(GetLastError());
break;
case WIN32_SYS_WINSOCK:
return PrintError(WSAGetLastError());
break;
default:
return "noerr";
}
}
#endif
//void my_new_handler()
//{
// cerr<<"not enough mem!\n";
// throw std::bad_alloc();
// exit(-1);
//}
//new_handler Old_Handler_ = set_new_handler(my_new_handler);
CException::CException(int iErrorNo, const char* sErrorMsg, const char* sFile, int iLine)
{
m_iErrorNo = iErrorNo;
if (sErrorMsg)
m_strErrorMsg = sErrorMsg;
if (sFile)
m_strFile = sFile;
m_iLine = iLine;
}
CException::CException(const char* sErrorMsg, const char* sFile, int iLine)
{
m_iErrorNo = EMPTY_ERROR_NO;
if (sErrorMsg)
m_strErrorMsg = sErrorMsg;
if (sFile)
m_strFile = sFile;
m_iLine = iLine;
}
ostream& operator << (ostream& os, const CException& e)
{
if (e.m_iErrorNo != CException::EMPTY_ERROR_NO)
os << e.m_iErrorNo << ":";
os << e.m_strErrorMsg;
if (!e.m_strFile.empty() && e.m_iLine != CException::EMPTY_ERROR_NO)
os << " [" << e.m_strFile << ":" << e.m_iLine << "]";
return os;
}
ostream& operator << (ostream& os, CNoMemException& e)
{
return os << (CException&)e;
}
ostream& operator << (ostream& os, CEOutOfBounds& e)
{
return os << (CException&)e;
}
ostream& operator << (ostream& os, CSocketException& e)
{
return os << (CException&)e;
}
ostream& operator << (ostream& os, CThreadException& e)
{
return os << (CException&)e;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -