首页 > 代码库 > 异常封装类
异常封装类
#ifndef _EXCEPT_H
#define _EXCEPT_H
#include <string>
using namespace std;
// Server exception
class CMyException : public exception {
public:
CMyException (void) :
m_msg ("Server Exception !") {}
CMyException (const string& msg) :
m_msg ("Server Exception : ") {
m_msg += msg;
m_msg += " !";
}
~CMyException (void) throw () {}
const char* what (void) const throw () {
return m_msg.c_str ();
}
private:
string m_msg;
};
// Database exception
class DBException : public CMyException {
public:
DBException (void) :
CMyException ("Database Exception") {}
DBException (const string& msg) :
CMyException (msg) {}
};
// Socket exception
class SocketException : public CMyException {
public:
SocketException (void) :
CMyException ("Socket Exception") {}
SocketException (const string& msg) :
CMyException (msg) {}
};
// Thread exception
class ThreadException : public CMyException {
public:
ThreadException (void) :
CMyException ("Thread Exception") {}
ThreadException (const string& msg) :
CMyException (msg) {}
};
// Login exception
class LoginException : public CMyException {
public:
LoginException (void) :
CMyException ("Login Exception") {}
LoginException (const string& msg) :
CMyException (msg) {}
};
class ClientHandlerException : public CMyException {
public:
ClientHandlerException (void) :
CMyException ("Login Exception") {}
ClientHandlerException (const string& msg) :
CMyException (msg) {}
};
#endif // _EXCEPT_H
=================================================================================
try
{
}catch(CMyException ex)
{
#ifdef _DEBUG
OutputDebugString("\r\n");
OutputDebugString(ex.what());
OutputDebugString("\r\n");
#endif
}
本文出自 “日知其所无” 博客,谢绝转载!
异常封装类