示例
Class::~Class() {
// Clean up references to memory ...
int
error = cleanUp();
if
(error)
{
throw
str;
}
logDestruction();
// May throw exception
}
解决方案
通过捕捉所有异常确保没有异常离开析构函数。
Class::~Class() {
try
{
// Clean up references to memory
delete
pointer;
logDestruction();
}
catch
( ... ) {
// catch all errors here
}
}