title: Catch ErrorException that wraps a fatal PHP error
body: <p>In my homemade PHP MVC framework, I've written a little error handler that wraps PHP errors in an exception, then throws it.</p>
  
  <pre><code>class ErrorController extends ControllerAbstract {
  
      ...
  
      public static function createErrorException($number, $message = NULL, $file = NULL, $line = NULL, array $context = array()) {
          throw new ErrorException($message, $number, 0, $file, $line);
      }
  }
  </code></pre>
  
  <p>Which is then registered using <code>set_error_handler()</code>. This works fine, with the exception (no pun intended) of fatal errors.  My custom error handler is still called, but I can't catch the <code>ErrorException</code> that is thrown.</p>
  
  <p>An example of such an error would be trying to include a file that doesn't exist:</p>
  
  <pre><code>    try {
          require 'Controller/NonExistentController.php';
      } catch (ErrorException $exc) {
          echo $exc-&gt;getTraceAsString(); // code never reaches this block
      }
  </code></pre>
  
  <p>My custom error handler is called and the exception is thrown, but the code never reaches the "catch" block. Instead, PHP generates HTML (bad!):</p>
  
  <blockquote>
    <p><br /> <b>Warning</b>:  Uncaught exception 'ErrorException' with
    message 'require(Controller/NonExistentController.php): failed to open stream: ...</p>
  </blockquote>
  
  <p>Followed by:</p>
  
  <blockquote>
    <p><b>Fatal error</b>:  Program::main(): Failed opening required
    'Controller/NonExistentController.php' (include_path='.:') in ...</p>
  </blockquote>
  
  <p>I do not want to attempt recovering from a fatal error, but I do want my code to exit gracefully. In this instance, that means sending back an XML or JSON response indicating an internal error, because this is a REST application and that's what my clients expect. HTML responses would most likely break the client applications as well.</p>
  
  <p>Should I go about this differently?</p>