router = $router; } public function onKernelException(ExceptionEvent $event) { // You get the exception object from the received event $exception = $event->getThrowable(); // HttpExceptionInterface is a special type of exception that // holds status code and header details if ($exception instanceof HttpExceptionInterface) { $route = $this->router->generate('error', ['status' => $exception->getStatusCode()]); } else { $route = $this->router->generate('error', ['status' => Response::HTTP_INTERNAL_SERVER_ERROR]); } // Customize your response object to display the exception details $response = new RedirectResponse($route); // sends the modified response object to the event $event->setResponse($response); } }