C++异常处理的警告
我最近写了一个类,利用了C++异常,并且另外继承了exception类CException,但是我没一个利用throw(CException)的成员函数在编译的时候都会发出警告:C4290:忽略C++异常规范,但指示函数不是__declspec(nothrow)。这是什么警告,什么原因引起的阿?我用的是VC7.1
代码如下:
using std::string;
using std::exception;
class CException :
public exception
{
protected:
string Method; //方法,异常的发出者
string Message; //错误消息
int Code; //错误代码
public:
CException( const string &s_Method, const string &s_Message, int n_code ) throw();
virtual ~CException( void ) throw();
const string& GetMethod( void ) const throw() { return Method; }
const string& GetMessage( void ) const throw() { return Message; }
const int GetCode( void ) const throw() { return Code; }
virtual const char* What( void ) const throw() { return GetMessage().c_str(); }
};
namespace JJunMethodName
{
const string NETINIT = "CSocket::init()";
const string NETDEINIT = "CSocket::deinit()";
}
namespace JJunErrorMessage
{
const string MSGNETINIT = "Winsock初始化时发生错误";
const string MSGNETDEINIT = "释放Winsock时发生错误";
}
class CSocket
{
private:
SOCKET m_hSocket;
//构造
public:
explicit CSocket(void) throw();
//属性
public:
//方法
public:
//执行
public:
~CSocket(void) throw();
//全局
public:
static void Init() throw(CException); //初始化Socket
static void Deinit() throw(CException); //注销Socket
};