My recommendation is to give a NULL check etc after every "new" call |
That doesn't make sense if you didn't overwrite global operator new with global operator nothrow-new which isn't a good idea anyways (if you don't do something crazy, like writing an application which has to run without runtime environment).
The terms under which a destructor is called automatically is very well documented in the standard. Anyone complaining has either a bad compiler or doesn't know the standard.
In a normal case a destructor is called automatically when an exception is thrown from the constructor or an object construction is failed. |
Which destructor(s)? If a constructor exits via the means of throwing an exception, the object isn't created and thus cannot be destroyed. However, already initialized base classes and (non static) members are destructed (in reverse order of construction, i.e. non-static member objects in reverse declaration order are first, virtual base classes depth-first, right-to-left last, and the rest in between), and the memory allocated by new is returned to the free store (if it wasn't a call of placement-new, that is).
If a failure occurs during destruction of an object and the object cannot handle the failure itself, then throwing is the only option. |
Destructors that throw are evil. It is an stl requirement that the classes used in conjunction with the stl don't throw from the destructors, as well as it is a requirement of operator new[] and delete[] (calling new[] or delete[] for an class whose destructor might throw invokes undefined behavior: suppose the 2nd destructor of a 5-element array would throw when delete[] is invoked, what do you do? Propagating the exception would leave no way to delete the other 3 elements! Same in new[]: if during the construction an element throws, the rest is destroyed automatically. But if one of the destructors then throws, you are screwed).
You should never let an exception escape a constructor |
Reporting errors from constructors was the initial idea of introducing exceptions into C++, since you cannot return error codes from them.