码迷,mamicode.com
首页 > 其他好文 > 详细

异常封装类

时间:2015-01-19 16:02:31      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:private   include   public   return   

#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

}


本文出自 “日知其所无” 博客,谢绝转载!

异常封装类

标签:private   include   public   return   

原文地址:http://shenyantao.blog.51cto.com/1957956/1605590

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!