title: PHP rethrow exception from constructor
body: <p>Just wanted to know if this is a common practice.  Basically the constructor is calling some initialization functions that throw on failure. My thinking is it makes sense just to rethrow the exception right back to where the object is being created since that's where actual output is being sent.  </p>
  
  <p>Is this "best practice" for this kind of situation? Or is there a more standard way to do this?</p>
  
  <pre><code>&lt;?php
    class a {   
          private $x;
          private $y;
          function __construct($filename) {
               try {
                   $this-&gt;x = $this-&gt;functionThatMightThrowException($filename);
                   $this-&gt;y = $this-&gt;doSomethingElseThatMightThrow();
               }
               catch(InvalidArgumentException $e) {
                    throw $e;    //is this a good practice or not???
               }
               catch(Exception $e) {
                    throw $e;    //again
               }
           }
  
           //rest of class definition
      }
  
    // then somewhere else where the object is created and output is being sent
    $fn = "blah.txt";
    try {
      $a = new a($fn);
    }
    catch (InvalidArgumentException $e) {
       //actually handle here -- send error message back etc
    } 
    catch (Exception $e) {
       //etc
    }
  ?&gt; 
  </code></pre>