src/ExceptionHandler.php
public function add(callable $callback)
    {
        $reflection = new \ReflectionFunction($callback);

        $params = $reflection->getParameters();
        if (empty($params)) {
            throw new \InvalidArgumentException(
                "Invalid exception callback: Has no arguments. Expected at least one."
            );
        }

        // Read the type hinted class for the first parameter
        $class = $params[0]->getClass();

        if ($class === null) {
            throw new \InvalidArgumentException(
                "Invalid exception callback: The first argument must have a class type hint."
            );
        }

        $this->callbacks[$class->name] = $callback;
    }
public function add(callable $callback)
    {
        $reflection = new \ReflectionFunction($callback);

        $params = $reflection->getParameters();
        if (empty($params)) {
            throw new \InvalidArgumentException(
                "Invalid exception callback: Has no arguments. Expected at least one."
            );
        }

        // Read the type hinted class for the first parameter
        $class = $params[0]->getClass();

        if ($class === null) {
            throw new \InvalidArgumentException(
                "Invalid exception callback: The first argument must have a class type hint."
            );
        }

        $this->callbacks[$class->name] = $callback;
    }
public function add ( callable $ callback ) { $ reflection = new \ ReflectionFunction ( $ callback ) ; $ params = $ reflection -> getParameters ( ) ; if ( empty ( $ params ) ) { throw new \ InvalidArgumentException ( "Invalid exception callback: Has no arguments. Expected at least one." ) ; } // Read the type hinted class for the first parameter $ class = $ params [ 0 ] -> getClass ( ) ; if ( $ class === null ) { throw new \ InvalidArgumentException ( "Invalid exception callback: The first argument must have a class type hint." ) ; } $ this -> callbacks [ $ class -> name ] = $ callback ; }
Adds an exception callback.

The exception callback should be a callable
function which has one argument, and that argument must have a type hint
of an exception class. It should return a
`Symfony\Component\HttpFoundation\Response` object.

For example:

```
$handler->add(function(SomeException $ex) {
return new Response("Something broke", Response::HTTP_INTERNAL_SERVER_ERROR);
});
```

It's possible to have multiple handlers and they will be checked in the
order they were added. So be careful to put more specific exceptions
before more generic ones (i.e. \Exception should come last).
Adds an exception callback .