4 ms·
Avoiding exceptions I can totally understand—that guideline is broadly understood, and right there in the Google C++ style guide. I'm struggling to understand
by mikepurvis 13y ago
Avoiding exceptions I can totally understand—that guideline is broadly understood, and right there in the Google C++ style guide.
I'm struggling to understand the business about constructors, though. Shouldn't a constructor be mostly just providing a sane initial state? What's it doing which has the possibility of needing to throw an exception? I think there's a reasonable middle-ground here, where you put the no-fail stuff in the language-provided constructor, and then have separate initialization functions (with return codes) which take care of the more brittle bits as necessary.
What's an example of an object which requires complex initialization? (I'm assuming that anything IO-related, like a socket, will for testing reasons have been passed in to the constructor rather than created by it.)