exception.h

来自「天之炼狱1服务器端源文件游戏服务端不完整」· C头文件 代码 · 共 649 行 · 第 1/2 页

H
649
字号
//////////////////////////////////////////////////////////////////////// // Filename    : Exception.h // Written By  : reiot@ewestsoft.com// Description :// //////////////////////////////////////////////////////////////////////#ifndef __EXCEPTION_H__#define __EXCEPTION_H__// include files#include "Types.h"#include "StringStream.h"#if __WINDOWS__#pragma warning (disable : 4786)#endif#include <list>////////////////////////////////////////////////////////////////////////// class Throwable//// Exception 苞 Error 狼 海捞胶 努贰胶捞促. 包访 皋筋靛 棺 单捞鸥甫// 备泅秦初绊 乐促.////////////////////////////////////////////////////////////////////////class Throwable : public std::exception{public:	// constructor	Throwable () throw () {}		// constructor	Throwable (const string& message) throw () : m_Message(message) {}	// destructor	virtual ~Throwable () throw () {}	// return class's name	virtual string getName () const throw () { return what(); }	// add function name to throwable object's function stack	void addStack (const string & stackname) throw ()	{		m_Stacks.push_front(stackname);	}	// return debug string - throwable object's function stack trace	string getStackTrace () const throw ()	{		StringStream buf;		int i = 1;		for (list<string>::const_iterator itr = m_Stacks.begin() ;			  itr != m_Stacks.end() ;			  itr ++, i ++) {			for (int j = 0 ; j < i ; j ++)				buf << " ";			buf << *itr << '\n' ;		}				return string(buf.toString());	}	// get throwable object's message	const string& getMessage () const throw () { return m_Message; }		// set throwable object's message	void setMessage (const string & message) throw () { m_Message = message; }		// return debug string - throwable object's detailed information	virtual string toString () const throw ()	{		StringStream buf;		buf << getName() << " : " << m_Message << '\n'			<< getStackTrace () ;				return string(buf.toString());	}private :		// message string	string m_Message;		// function stack 	list<string> m_Stacks;};//--------------------------------------------------------------------------------// macro definition//--------------------------------------------------------------------------------//--------------------------------------------------------------------------------//// Throwable捞 鞘夸窍扁 锭巩俊 酒贰俊 沥狼沁促.// Exception/Error甫 带瘤绰 葛电 皋筋靛狼 困/酒贰俊 疙矫登绢具 茄促.// __END_CATCH绰 Throwable狼 皋家靛 胶琶俊 殿废茄 饶 惑困肺 带瘤绰// 开且阑 茄促.////--------------------------------------------------------------------------------#if defined(NDEBUG)	#define __BEGIN_TRY ((void)0);	#define __END_CATCH ((void)0);#else	#define __BEGIN_TRY try {	#define __END_CATCH } catch (Throwable & t) { t.addStack(__PRETTY_FUNCTION__); throw; }#endif// 皋技瘤 厚免仿 END_CATCH//#define __END_CATCH } catch (Throwable & t) { t.addStack(__PRETTY_FUNCTION__); throw; }// 皋技瘤 免仿 END_CATCH//#define __END_CATCH } catch (Throwable & t) { cout << "\nCAUGHT Exception IN END_CATCH MACRO...\n[" << __PRETTY_FUNCTION__ << "]\n>>> " << t.toString() << endl; t.addStack(__PRETTY_FUNCTION__); throw; }/*//--------------------------------------------------------------------------------////	#define __BEGIN_TRY \//				try {//	#define __END_CATCH \//				} catch (Throwable & t) { \//					t.addStack((func)); \//					throw; \//				}////// critical section////--------------------------------------------------------------------------------*/#define __ENTER_CRITICAL_SECTION(mutex) mutex.lock(); try {#define __LEAVE_CRITICAL_SECTION(mutex) } catch (Throwable & t) { mutex.unlock(); throw; } mutex.unlock(); //--------------------------------------------------------------------------------//// cout debugging////--------------------------------------------------------------------------------#if defined(NDEBUG) || defined(__WIN32__)	#define __BEGIN_DEBUG ((void)0);	#define __END_DEBUG ((void)0);#elif defined(__LINUX__) || defined(__WIN_CONSOLE__)	#define __BEGIN_DEBUG try {	#define __END_DEBUG  } catch (Throwable & t) { cout << t.toString() << endl; throw; } catch (exception & e) { cout << e.what() << endl; throw; }#elif defined(__MFC__)	#define __BEGIN_DEBUG try {	#define __END_DEBUG } catch (Throwable & t) { AfxMessageBox(t.toString()); throw; }#endif////////////////////////////////////////////////////////////////////////// Exception////////////////////////////////////////////////////////////////////////class Exception : public Throwable {public :	Exception () throw () : Throwable() {}	Exception (const string& msg) throw () : Throwable(msg) {}	string getName () const throw () { return "Exception"; }};	//////////////////////////////////////////////////////////////////////	//	// I/O Exception	//	// 颇老, 家南, IPC 涝免仿矫 惯积且 荐 乐绰 抗寇	//	//////////////////////////////////////////////////////////////////////	// 颇老, 家南, IPC 涝免仿矫 惯积且 荐 乐绰 抗寇	class IOException : public Exception {	public :		IOException () throw () : Exception () {}		IOException (const string& msg) throw () : Exception (msg) {}		string getName () const throw () { return "IOException"; }	};		//////////////////////////////////////////////////////////////////////		//		// Non Blocking I/O Exception		//		// I/O 矫 nonblocking 捞 惯积且 版快		//		//////////////////////////////////////////////////////////////////////		class NonBlockingIOException : public IOException {		public :			NonBlockingIOException () throw () : IOException () {}			NonBlockingIOException (const string& msg) throw () : IOException (msg) {}			string getName () const throw () { return "NonBlockingIOException"; }		};			//////////////////////////////////////////////////////////////////////		//		// Interrupted I/O Exception		//		// I/O 矫 牢磐反飘啊 吧赴 版快		//		//////////////////////////////////////////////////////////////////////		class InterruptedIOException : public IOException {		public :			InterruptedIOException () throw () : IOException () {}			InterruptedIOException (const string& msg) throw () : IOException (msg) {}			string getName () const throw () { return "InterruptedIOException"; }		};			//////////////////////////////////////////////////////////////////////		//		// EOF Exception		//		// I/O 矫 EOF 甫 父抄 版快		//		//////////////////////////////////////////////////////////////////////		class EOFException : public IOException {		public :			EOFException () throw () : IOException () {}			EOFException (const string& msg) throw () : IOException (msg) {}			string getName () const throw () { return "EOFException"; }		};			//////////////////////////////////////////////////////////////////////		//		// File Not Opened Exception 		//		//////////////////////////////////////////////////////////////////////		class FileNotOpenedException : public IOException {		public :			FileNotOpenedException () throw () : IOException() {}			FileNotOpenedException (const string& msg) throw () : IOException(msg) {}			string getName () const throw () { return "FileNotOpenedException"; }		};		//////////////////////////////////////////////////////////////////////		//		// File Already Exist Exception		//		//////////////////////////////////////////////////////////////////////		class FileAlreadyExistException : public IOException {		public :			FileAlreadyExistException () throw () : IOException() {}			FileAlreadyExistException (const string& msg) throw () : IOException(msg) {}			string getName () const throw () { return "FileAlreadyExistException"; }		};		//////////////////////////////////////////////////////////////////////		//		// File Not Exist Exception		//		//////////////////////////////////////////////////////////////////////		class FileNotExistException : public IOException {		public :			FileNotExistException () throw () : IOException() {}			FileNotExistException (const string& msg) throw () : IOException(msg) {}			string getName () const throw () { return "FileNotExistException"; }		};		//////////////////////////////////////////////////////////////////////		//		// Time out Exception		//		// 瘤沥 矫埃捞 瘤车阑 版快		//		//////////////////////////////////////////////////////////////////////		class TimeoutException : public IOException {		public :			TimeoutException () throw () : IOException () {}			TimeoutException (const string& msg) throw () : IOException (msg) {}			string getName () const throw () { return "TimeoutException"; }		};		//////////////////////////////////////////////////////////////////////		//		// Socket Exception		//		// 漂洒 家南俊辑 惯积窍绰 抗寇甸		//		//////////////////////////////////////////////////////////////////////		class SocketException : public IOException {		public :			SocketException () throw () : IOException () {}			SocketException (const string& msg) throw () : IOException (msg) {}			string getName () const throw () { return "SocketException"; }		};				//////////////////////////////////////////////////////////////////////			//			// Bind Exception			//			// bind()矫 惯积窍绰 抗寇			//			//////////////////////////////////////////////////////////////////////			class BindException : public SocketException {			public :				BindException () throw () : SocketException () {}				BindException (const string& msg) throw () : SocketException (msg) {}				string getName () const throw () { return "BindException"; }			};				//////////////////////////////////////////////////////////////////////			//			// Connect Exception			//			// 家南 楷搬捞 谗辨 版快 (啊厘 腹捞 惯积茄促绊 焊搁 等促.)			//			//////////////////////////////////////////////////////////////////////			class ConnectException : public SocketException {			public :				ConnectException () throw () : SocketException () {}				ConnectException (const string& msg) throw () : SocketException (msg) {}				string getName () const throw () { return "ConnectException"; }			};					//////////////////////////////////////////////////////////////////////		//		// Protocol Exception		//		// 菩哦 颇教且锭 惯积窍绰 抗寇甸

⌨️ 快捷键说明

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