title: How to return error code from constructor?
body: <p>I am trying to return error code from constructor, since constructor
  does not return an error code, I tried to put an exception on the
  constructor. Then in the catch block I return my appropriate error code.
  Is this a proper way of returning error code from constructor ?</p>
  
  <pre><code>#include &lt;exception&gt;
  #include &lt;iostream&gt;
  
  class A {
   public:
    A() { throw std::runtime_error("failed to construct"); }
  };
  
  int main() {
    try {
      A a;
    } catch (const std::exception&amp; e) {
      std::cout &lt;&lt; "returining error 1 \n";
      return 1;
    }
  
    return 0;
  }
  </code></pre>