It should throw an exception. Some authors suggest that constructors should not throw exceptions. In general this is wrong. For example, constructors cannot return an error code, so attempting to use error codes is inappropriate. Besides, a failed constructor usually indicates that the object did not achieve a self-consistent state (for example, it may not have been able to allocate sufficient memory, the appropriate file may not have existed, and so on). It is error-prone to let these objects continue to live. For example, if some other member function of the object used a nonexistent resource, it would be an error. If a constructor experiences an error and the programmer cannot throw an exception, another alternative is to mark the object as a zombie (see FAQ 26.05). |