title: How to implement exception chaining in PHP
body: <p>Constructor for PHP's exception has third parameter, <a href="http://www.php.net/manual/en/exception.construct.php" rel="noreferrer">documentation</a> says:</p>
  
  <pre><code>$previous: The previous exception used for the exception chaining. 
  </code></pre>
  
  <p>But I can't make it work. My code looks like this:</p>
  
  <pre><code>try
  {
      throw new Exception('Exception 1', 1001);
  }
  catch (Exception $ex)
  {
      throw new Exception('Exception 2', 1002, $ex);
  }
  </code></pre>
  
  <p>I expect Exception 2 to be thrown and I expect that it will have Exception 1 attached. But all I get is:</p>
  
  <pre><code>Fatal error: Wrong parameters for Exception([string $exception [, long $code ]]) in ...
  </code></pre>
  
  <p>What am I doing wrong?</p>