Two phase Construction in C++

A document about Two Phase Construction.

The idea is that you cannot return a value from a constructor to indicate failure. The only way to indicate constructor failure is to throw an exception. This is not always desirable, not least because exception safety is a very complex topic.

So in this case the construction is split up: a constructor that does not throw, but also does not fully initialize, and a function that does the initialization and can return an indication of success or failure without (necessarily) throwing exceptions.


There is no good reason to do this - avoid. The original author of the code probably simply didn't know what they were doing.

Tags:

C++

Sdk