title: Stop C++ Class Instantiation
body: <p>Is there a way to stop a C++ class if there is an error in the instantiation? Like, return NULL maybe? Basically I have a wrapper class for MySQL, and the constructor does the connecting, but if the connection fails, I want the object to be, um, useless?</p>
  
  <pre><code>PDB::PDB(string _DB_IP, string _DB_USER, string _DB_PASS, string _DB_DB)
    : _DB_IP( _DB_IP ), _DB_USER( _DB_USER ), _DB_PASS( _DB_PASS ), _DB_DB( _DB_DB )
  {
    mysql_init(&amp;this-&gt;mysql);
  
    this-&gt;connection = mysql_real_connect(&amp;this-&gt;mysql, this-&gt;_DB_IP.c_str(), this-&gt;_DB_USER.c_str(), this-&gt;_DB_PASS.c_str(), this-&gt;_DB_DB.c_str(), 0, 0, 0);
  
    if( this-&gt;connection == NULL ) // WHAT SHOULD I DO HERE, OTHER THAN THROW AN ERROR?
      {
        cout &lt;&lt; mysql_error(&amp;this-&gt;mysql) &lt;&lt; endl;
      }
  
    this-&gt;result = NULL;
  }
  </code></pre>
  
  <p>What should I do in the NULL test, to stop creation, etc?</p>