I know that a destructor should not throw an exception.
http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.13
I have the following code:
~a()
{
cleanup();
}
// I do not expect exception being thrown in this function.
// If exception really happen, I know that it is something not recoverable.
void a::cleaup()
{
delete p;
}
In my static analysis of the source code, he complains that I will call the cleanup function as follows:
~a()
{
try {
cleanup();
}
catch(...) {
// What to do? Print out some logging message?
}
}
// I do not expect exception being thrown in this function.
// If exception really happen, I know that it is something not recoverable.
void a::cleaup()
{
delete p;
}
I'm not sure if it is good practice to put a try ... catch block in a destructor, whenever it calls functions. How:
(1) If the cleanup function can throw an exception, I know something bad happened. I prefer it to be fail-fast . That is, just let the whole system crash, and let the programmer debug it.
(2) Overhead occurs when entering and exiting the try ... catch block.
(3) , ... .
, ... catch .
.