Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::setException PHP Method

setException() public method

This exception will be thrown if no response is set in the event.
public setException ( Exception $exception )
$exception Exception The thrown exception
    public function setException(\Exception $exception)
    {
        $this->exception = $exception;
    }

Usage Example

Example #1
0
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($this->env != "prod") {
         $event->setException($exception);
         return;
     }
     try {
         $code = 404;
         if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
             $code = 404;
         } else {
             if ($exception instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException) {
                 $code = 403;
             }
         }
         $file = $code;
         if ($this->env != "prod") {
             //$file = $file . '.' . $this->env;
         }
         $file = $file . '.html.twig';
         $template = $this->siteManager->getTemplate("portal");
         $template = "SymbbTemplateDefaultBundle:Exception:" . $file;
         $response = new Response($this->templating->render($template, array('status_code' => $code, 'status_text' => $exception->getMessage(), 'exception' => $exception)));
         // setup the Response object based on the caught exception
         $event->setResponse($response);
     } catch (\Exception $exc) {
         $event->setException($exception);
     }
     // you can alternatively set a new Exception
     // $exception = new \Exception('Some special exception');
     // $event->setException($exception);
 }
All Usage Examples Of Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::setException