📄 exception.cpp
字号:
#pragma VERSIONID "@(#)Exception.cpp version 1.0"
#include "Exception.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
Exception::Exception(const int errClass, const int errCode, const char *eventMsg)
{
_class = errClass;
_code = errCode;
_eventMsg = new char[strlen(eventMsg) + 1]; //动态分配的内存空间
strcpy(_eventMsg, eventMsg);
}
Exception::Exception(const Exception& exception)
{
_class = exception._class;
_code = exception._code;
_eventMsg = new char[strlen(exception._eventMsg) + 1]; //动态分配的内存空间
strcpy(_eventMsg, exception._eventMsg);
}
Exception& Exception::operator=(const Exception& other)
{
if (&other == this)
return *this;
if (0 != _eventMsg)
{
delete [] _eventMsg; //释放动态分配的内存空间
}
_class = other._class;
_code = other._code;
_eventMsg = new char[strlen(other._eventMsg) + 1]; //动态分配的内存空间
strcpy(_eventMsg, other._eventMsg);
return *this;
}
Exception::~Exception ()
{
if (0 != _eventMsg)
{
delete [] _eventMsg; //释放动态分配的内存空间
}
}
void throwException(int nClass,int nCode,const char *pMsg,...)
{
char pBuf[1025];
va_list pArgs;
va_start(pArgs, pMsg);
vsnprintf(pBuf,1025,pMsg,pArgs);
va_end(pArgs);
Exception e( nClass,nCode,pBuf );
throw e;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -