title: How to handle incorrect values in a constructor?
body: <p><strong>Please note that this is asking a question about constructors, not about classes which handle time.</strong></p>
  
  <p>Suppose I have a class like this:</p>
  
  <pre><code>class Time
  {
  protected:
      unsigned int m_hour;
      unsigned int m_minute;
      unsigned int m_second;
  public:
      Time(unsigned int hour, unsigned int minute, unsigned int second);
  };
  </code></pre>
  
  <p>While I would want a to be constructed successfully, I would want the constructor of b to fail.</p>
  
  <pre><code>Time a = Time(12,34,56);
  Time b = Time(12,34,65); // second is larger than 60
  </code></pre>
  
  <p>However, this is not possible, because constructors do not return any values and will always succeed.</p>
  
  <p>How would the constructor tell the program that it is not happy? I have thought of a few methods:</p>
  
  <ol>
  <li>have the constructor throw an exception, and have handlers in the calling function to handle it.</li>
  <li>have a flag in the class and set it to true only if the values are acceptable by the constructor, and have the program check the flag immediately after construction.</li>
  <li>have a separate (probably static) function to call to check the input parameters immediately before calling the constructor.</li>
  <li>redesign the class so that it can be constructed from any input parameters.</li>
  </ol>
  
  <p>Which of these methods is most common in industry? Or is there anything I may have missed?</p>