Contao\CoreBundle\EventListener\ExceptionConverterListener::onKernelException PHP Method

onKernelException() public method

Maps known exceptions to HTTP exceptions.
public onKernelException ( GetResponseForExceptionEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        $class = $this->getTargetClass($exception);
        if (null === $class) {
            return;
        }
        if (null !== ($httpException = $this->convertToHttpException($exception, $class))) {
            $event->setException($httpException);
        }
    }

Usage Example

 /**
  * Tests converting the derived PageNotFoundException exception.
  */
 public function testConvertDerivedPageNotFoundException()
 {
     $event = new GetResponseForExceptionEvent($this->mockKernel(), new Request(), HttpKernelInterface::MASTER_REQUEST, new DerivedPageNotFoundException());
     $listener = new ExceptionConverterListener();
     $listener->onKernelException($event);
     $exception = $event->getException();
     $this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException', $exception);
     $this->assertInstanceOf('Contao\\CoreBundle\\Exception\\PageNotFoundException', $exception->getPrevious());
 }
All Usage Examples Of Contao\CoreBundle\EventListener\ExceptionConverterListener::onKernelException