3 ms·
throwing an exception in the constructor comes to mind, in which case the destructor isn't called Of course it is not called -- the object has failed to constr
by boris 16y ago
throwing an exception in the constructor comes to mind, in which case the destructor isn't called
Of course it is not called -- the object has failed to construct. There is no object. You cannot call a destructor on nothing. Now if some data member has been constructed but the call constructor failed, destructors for such members will be called.
- stingraycharles 16y agoThe constructor might be partially executed before the exception is thrown (for example, allocated memory or locked resources), in which case those things don't get cleaned up. I'm not arguing it isn't correct behavior, it's just that things don't always seem as easy and straightforward as they look on first sight.