5 ms·
You can also use out parameters to tell about errors.
by fpoling 5y ago
You can also use out parameters to tell about errors.
- Koshkin 5y agoThis won't work with third-party callers.
- johannes1234321 5y agoWhen doing that the better approach is to use a factory function wrapping this. However mind that if you don't throw from C++'s perspective the object is fully created, so that the destructor will run. If you throw an exception from the contractor, the object won't be fully created.
- fpoling 5y agoIn practice I have not found that running destructor is problematic. In many cases the destructor is the default one that just destructs the fields. When the destructor should be non-default the constructor can leave the object in the move out state either explicitly or via hacks like using T tmp(std::move((*this)) on the error return in the constructor.