Skip to content

Change ExceptionListener to ErrorListener #13335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions create_framework/http_kernel_httpkernel_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ framework: it matches the incoming request and populates the request
attributes with route parameters.

Our code is now much more concise and surprisingly more robust and more
powerful than ever. For instance, use the built-in ``ExceptionListener`` to
powerful than ever. For instance, use the built-in ``ErrorListener`` to
make your error management configurable::

$errorHandler = function (Symfony\Component\ErrorHandler\Exception\FlattenException $exception) {
$msg = 'Something went wrong! ('.$exception->getMessage().')';

return new Response($msg, $exception->getStatusCode());
};
$dispatcher->addSubscriber(new HttpKernel\EventListener\ExceptionListener($errorHandler));
$dispatcher->addSubscriber(new HttpKernel\EventListener\ErrorListener($errorHandler));

``ExceptionListener`` gives you a ``FlattenException`` instance instead of the
``ErrorListener`` gives you a ``FlattenException`` instance instead of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it gives you a FlattenException instance if it's typehined as such in your controller or if the exception argument is not typed at all, otherwise it will give you a \Throwable instance.

thrown ``Exception`` or ``Error`` instance to ease exception manipulation and
display. It can take any valid controller as an exception handler, so you can
create an ErrorController class instead of using a Closure::

$listener = new HttpKernel\EventListener\ExceptionListener(
$listener = new HttpKernel\EventListener\ErrorListener(
'Calendar\Controller\ErrorController::exception'
);
$dispatcher->addSubscriber($listener);
Expand Down