title: Network connection setup in constructor: good or bad?
body: <p>I'm working on a class that handles interaction with a remote process that may or may not be available; indeed in most cases it won't be. If it's not, an object of that class has no purpose in life and needs to go away. </p>
  
  <p>Is it less ugly to:</p>
  
  <ol>
  <li>Handle connection setup in the constructor, throwing an exception if the process isn't there.</li>
  <li>Handle connection setup in a separate <code>connect()</code> method, returning an error code if the process isn't there.</li>
  </ol>
  
  <p>In option 1), the calling code will of course have to wrap its instantiation of that class and everything else that deals with it in a <code>try()</code> block. In option 2, it can simply check the return value from connect(), and return  (destroying the object) if it failed, but it's less RAII-compliant,</p>
  
  <p>Relatedly, if I go with option 1), is it better to throw one of the std::exception classes, derive my own exception class therefrom, roll my own underived exception class, or just throw a string? I'd like to include some indication of the failure, which seems to rule out the first of these.</p>
  
  <p>Edited to clarify: The remote process is on the same machine, so it's pretty unlikely that the <code>::connect()</code> call will block. </p>