📄 exception.h
字号:
#ifndef EXCEPTION_H
#define EXCEPTION_H
#include <string>
#include <iosfwd>
#include <errno.h>
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <WINDOWS.H>
#include <Winsock2.h>
#endif
#include "mylibconf.h"
namespace mylib{
#if defined(WIN32)
const char* PrintError(DWORD errnumber);
const char* STRERROR_WIN(int a);
const int WIN32_SYS = 1;
const int WIN32_SYS_WINSOCK= 2;
#endif
enum
{
NOMORL_ = 0,
DOWN_ = -99,
TIMEROUT_ = -98,
END_ = -97,
UNKNOWNERR_= -96,
PASS_ERR_ = -95,
INITED_ = 5
};
class CException
{
public:
enum { EMPTY_ERROR_NO = 32767, EMPTY_LINE = -1 };
protected:
int m_iErrorNo;
std::string m_strErrorMsg;
std::string m_strFile;
int m_iLine;
public:
CException(int iErrorNo, const char* sErrorMsg, const char* sFile = NULL, int iLine = EMPTY_LINE);
CException(const char* sErrorMsg, const char* sFile = NULL, int iLine = EMPTY_LINE);
//CException(string sErrorMsg,const char* sFile = NULL, int iLine = EMPTY_LINE);
std::string GetErrMsg(){return m_strErrorMsg;}
int ErrorNo() { return m_iErrorNo; }
virtual ~CException() {}
friend std::ostream& operator << (std::ostream& os, const CException& e);
};
class CNoMemException: public CException
{
public:
CNoMemException(const char* sErrorMsg, const char* sFile = NULL, int iLine = CException::EMPTY_LINE)
: CException(sErrorMsg, sFile, iLine) {}
friend std::ostream& operator << (std::ostream& os, CNoMemException& e);
};
class CEOutOfBounds:public CException
{
public:
CEOutOfBounds(const char* sErrorMsg, const char* sFile = NULL, int iLine = CException::EMPTY_LINE)
: CException(sErrorMsg, sFile, iLine) {}
friend std::ostream& operator << (std::ostream& os, CEOutOfBounds& e);
};
class CSocketException : public CException
{
public:
CSocketException(const char* sErrorMsg, const char* sFile = NULL, int iLine = CException::EMPTY_LINE,int Reason=UNKNOWNERR_)
: CException(sErrorMsg, sFile, iLine),userErrReason(Reason){}
virtual ~CSocketException() {}
int GetReason(){return userErrReason;}
friend std::ostream& operator << (std::ostream& os, CSocketException& e);
private:
int userErrReason;
};
class CThreadException : public CException
{
public:
CThreadException(const char* sErrorMsg, const char* sFile = NULL, int iLine = CException::EMPTY_LINE)
: CException(sErrorMsg, sFile, iLine) {}
virtual ~CThreadException() {}
friend std::ostream& operator << (std::ostream& os, CThreadException& e);
};
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -