3 ms·
In my company we do so by disallowing constructors to fail. If an object needs to be initialized with the potential of failure you need to call an init() functi
by ginko 5y ago
In my company we do so by disallowing constructors to fail. If an object needs to be initialized with the potential of failure you need to call an init() function that returns an error code after construction.
Yes, that makes RAII basically impossible.
- ahartmetz 5y agoIMO the most important part of RAII is really the other side, "destruction is resource divestment" - and that still works. That is the main purpose of lock guards, refcounting wrappers, file objects and so on.
- kllrnohj 5y agoWhy not a factory function that returns std::optional<T> instead? Or better a variant of T or error code? The construct-then-init pattern is so annoying to deal with.