exception.h

来自「用c++编写的网络通信框架」· C头文件 代码 · 共 43 行

H
43
字号
/*-----------------------------------------------------------------------------
 * FILE: framework.h
 * AUTH: xuwannian@gmail.com
 * TIME: 2008-04-29
 *---------------------------------------------------------------------------*/
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__

#include <memory.h>

class CException
{
public:
	CException(const char* _message, const char* _file, unsigned int _line, int _code=0) : 
		__line(_line), __code(_code)
	{
		::memset(__message, 0, sizeof(__message));
		::memset(__file	  , 0, sizeof(__file   ));
		if (_message)	::memcpy(__message, _message, (::strlen(_message) > sizeof(__message)) ? sizeof(__message) : ::strlen(_message));
		if (_file   )	::memcpy(__file   , _file   , (::strlen(_file   ) > sizeof(__file   )) ? sizeof(__file   ) : ::strlen(_file   ));

		ShowException();
	}

	char* What()		{ return this->__message;	};
	unsigned int Line() { return this->__line;		};

	void ShowException()
	{
		printf("-----------------------------Exception-------------------------------\n");
		printf("FILE: %s\nLINE: %d\nEXCP: %s\nCODE: %d\n", __file, __line, __message, __code);
		printf("---------------------------------------------------------------------\n");
	}

	~CException() {};
private:
	char			__message[256];
	unsigned int	__line;
	char			__file[256];
	int				__code;	// 错误类型,
}; // end class

#endif

⌨️ 快捷键说明

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