c++ - Shall I place try...catch block in destructor, if I know my function won't throw exception -
I know that the destroyer should not leave the exception.
I have the following code:
~ a () {cleanup}; } // I do not expect the exception being thrown at this function. // If the exception is actually, then I know that it is not recoverable: zero: clap () {delete p; }
In my static source code analysis, it complains that I will call the cleaning work like this:
~ a () {try { Cleanup (); } Hold (...) {// what to do? Print some logging messages? }} // I'm not expecting an exception to be thrown in this function. // If the exception is actually, then I know that it is not recoverable: zero: clap () {delete p; }
I'm not sure that this is a good practice, to try ... block the block in the constructor, whenever this function calls. As::
(1) If the cleanup function is able to leave the exception, then I know that something bad happened. I like this, just let the whole system crash, and programmers debug it.
(2) Overhead is generated when entering and exiting ... Catch block.
(3) The code looks rigid, with lots of attempts ... hold the block around the square destroyer.
I can remember some other points, why try ... the grip block should be in place.
Thank you.
Since delete
does not throw, neither cleanup
And there is no need to put the call in an attempt to try it.
Since your static analysis tool is probably finding difficult times, perhaps by declaring it as a cleanup
non-throw (this is just an estimate).
zero cleanup () throw ();
Comments
Post a Comment