title: Silex: error handlers for specific exception types
body: <p>It it possible in Silex to use an error handler based on what exception is thrown?</p>
  
  <p>I know this is possible with a single exception handler and a switch statement on the classname of the thrown exception but to me it seems the "Silex way" is cleaner, yet doesn't work.</p>
  
  <p>This is how I would expect it to work</p>
  
  <pre><code>&lt;?php
  // Handle access denied errors
  $app-&gt;error(function (\App\Rest\Exception\AccessDenied $e) {
      $message = $e-&gt;getMessage() ?: 'Access denied!';
      return new Response($message, 403);
  });
  // Handle Resource not found errors
  $app-&gt;error(function (\App\Rest\Exception\ResourceNotFound $e) {
      $message = $e-&gt;getMessage() ?: 'Resource not found!';
      return new Response($message, 404);
  });
  // Handle other exception as 500 errors
  $app-&gt;error(function (\Exception $e, $code) {
      return new Response($e-&gt;getMessage(), $code);
  });
  </code></pre>
  
  <p>Problem is that when I throw a ResourceNotFound exception in my controller, the errorhandler tied to AccessDenied is executed</p>
  
  <blockquote>
    <p>Catchable fatal error: Argument 1 passed to {closure}() must be an instance of App\Rest\Exception\AccessDenied, instance of App\Rest\Exception\ResourceNotFound given</p>
  </blockquote>
  
  <p>Is this achievable in another way or should I just stuff everything in the handler that works with generic Exceptions and switch on the type of exception thrown?</p>
  
  <p>PS: i'm aware of the <code>$app-&gt;abort()</code> method but prefer working with exceptions</p>