function 'Symbol' may throw an exception in destructor 'Symbol' -- A call to a
function (name given by the first Symbol) was made from within a destructor. The function
294
was declared as potentially throwing an exception. Such exceptions need to be caught within a
try block because destructors should never throw exceptions.
这个是根据More Effective C++ Item 11: Prevent exceptions from leaving destructors. 制定的规则.
即防止析构函数中出现异常.
解决方式,即在声明要抛出异常的函数加
try
{}
catch(...)
{
// 这里面什么都不做
}
然而非常不好的情况在于,比如说下面这个
CX::~CX
{
try {
delete p1;
}
catch(...)
try{
delete p2;
}
catch(...)
p1 = 0;
p2 = 0;
}
如果多了呢?万一有多条语句,这可就惨了.看样子对类要好好设计,一点点的细节要影响这么多事情.