How to handle incorrect values in a constructor?

后端 未结 11 1358
野性不改
野性不改 2020-12-17 08:44

Please note that this is asking a question about constructors, not about classes which handle time.

Suppose I have a class like this:



        
11条回答
  •  攒了一身酷
    2020-12-17 09:26

    "Exception thrown from a C'tor" is not a four-letter word. If an object can not be created correctly, the C'tor should fail, because you'd rather fail in construction than having an invalid object.

提交回复
热议问题