diff --git a/components/http_kernel.rst b/components/http_kernel.rst index 046ca09a6f6..b1c98d7cae2 100644 --- a/components/http_kernel.rst +++ b/components/http_kernel.rst @@ -526,10 +526,22 @@ to the exception. Each listener to this event is passed a :class:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent` object, which you can use to access the original exception via the -:method:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent::getException` +:method:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent::getThrowable` method. A typical listener on this event will check for a certain type of exception and create an appropriate error ``Response``. +.. versionadded:: 4.4 + + The :method:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent::getThrowable` and + :method:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent::setThrowable` methods + were introduced in Symfony 4.4. + +.. deprecated:: 4.4 + + The :method:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent::getException` and + :method:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent::setException` methods + are deprecated since Symfony 4.4. + For example, to generate a 404 page, you might throw a special type of exception and then add a listener on this event that looks for this exception and creates and returns a 404 ``Response``. In fact, the HttpKernel component diff --git a/event_dispatcher.rst b/event_dispatcher.rst index c1c7d1c6f95..8df171497a5 100644 --- a/event_dispatcher.rst +++ b/event_dispatcher.rst @@ -35,7 +35,7 @@ The most common way to listen to an event is to register an **event listener**:: public function onKernelException(ExceptionEvent $event) { // You get the exception object from the received event - $exception = $event->getException(); + $exception = $event->getThrowable(); $message = sprintf( 'My Error says: %s with code: %s', $exception->getMessage(), diff --git a/reference/events.rst b/reference/events.rst index d6d7b669573..b7eec4d8dbd 100644 --- a/reference/events.rst +++ b/reference/events.rst @@ -239,14 +239,14 @@ sent as response:: public function onKernelException(ExceptionEvent $event) { - $exception = $event->getException(); + $exception = $event->getThrowable(); $response = new Response(); // setup the Response object based on the caught exception $event->setResponse($response); // you can alternatively set a new Exception // $exception = new \Exception('Some special exception'); - // $event->setException($exception); + // $event->setThrowable($exception); } .. note::