title: When to use ErrorException vs Exception?
body: <p>PHP 5.1 has introduced <a href="http://php.net/manual/en/class.errorexception.php">ErrorException</a>. The constructor of the two functions differs</p>
  
  <pre><code>public __construct ([ string $message = "" [, int $code = 0 [, Exception $previous = NULL ]]] )
  public __construct ([ string $message = "" [, int $code = 0 [, int $severity = 1 [, string $filename = __FILE__ [, int $lineno = __LINE__ [, Exception $previous = NULL ]]]]]] )
  </code></pre>
  
  <p>Is there a difference when to use either?</p>
  
  <p>I suspect that the above use case is incorrect:</p>
  
  <pre><code>&lt;?php
  class Data {
      public function save () {
          try {
              // do something
          } catch (\PDOException $e) {
              if ($e-&gt;getCode() == '23000') {
                  throw new Data_Exception('Foo Bar', $e);
              }
  
              throw $e
          }
      }
  }
  
  class Data_Exception extends ErrorException /* This should not be using ErrorException */ {}
  </code></pre>
  
  <p>It isn't documented well, but it appears that <code>ErrorException</code> is designed to be used explicitly from the custom error handler as in the original example, <a href="http://php.net/manual/en/class.errorexception.php">http://php.net/manual/en/class.errorexception.php</a>.</p>
  
  <pre><code>function exception_error_handler($errno, $errstr, $errfile, $errline ) {
      throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
  }
  set_error_handler("exception_error_handler");
  </code></pre>