File tree 3 files changed +16
-4
lines changed
3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -526,10 +526,22 @@ to the exception.
526
526
527
527
Each listener to this event is passed a :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent `
528
528
object, which you can use to access the original exception via the
529
- :method: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent::getException `
529
+ :method: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent::getThrowable `
530
530
method. A typical listener on this event will check for a certain type of
531
531
exception and create an appropriate error ``Response ``.
532
532
533
+ .. versionadded :: 4.4
534
+
535
+ The :method: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent::getThrowable ` and
536
+ :method: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent::setThrowable ` methods
537
+ were introduced in Symfony 4.4.
538
+
539
+ .. deprecated :: 4.4
540
+
541
+ The :method: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent::getException ` and
542
+ :method: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent::setException ` methods
543
+ are deprecated since Symfony 4.4.
544
+
533
545
For example, to generate a 404 page, you might throw a special type of exception
534
546
and then add a listener on this event that looks for this exception and
535
547
creates and returns a 404 ``Response ``. In fact, the HttpKernel component
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ The most common way to listen to an event is to register an **event listener**::
35
35
public function onKernelException(ExceptionEvent $event)
36
36
{
37
37
// You get the exception object from the received event
38
- $exception = $event->getException ();
38
+ $exception = $event->getThrowable ();
39
39
$message = sprintf(
40
40
'My Error says: %s with code: %s',
41
41
$exception->getMessage(),
Original file line number Diff line number Diff line change @@ -239,14 +239,14 @@ sent as response::
239
239
240
240
public function onKernelException(ExceptionEvent $event)
241
241
{
242
- $exception = $event->getException ();
242
+ $exception = $event->getThrowable ();
243
243
$response = new Response();
244
244
// setup the Response object based on the caught exception
245
245
$event->setResponse($response);
246
246
247
247
// you can alternatively set a new Exception
248
248
// $exception = new \Exception('Some special exception');
249
- // $event->setException ($exception);
249
+ // $event->setThrowable ($exception);
250
250
}
251
251
252
252
.. note ::
You can’t perform that action at this time.
0 commit comments