You are here

public function ExceptionListener::onKernelException in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/EventListener/ExceptionListener.php \Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException()

File

vendor/symfony/http-kernel/EventListener/ExceptionListener.php, line 40

Class

ExceptionListener
ExceptionListener.

Namespace

Symfony\Component\HttpKernel\EventListener

Code

public function onKernelException(GetResponseForExceptionEvent $event) {
  $exception = $event
    ->getException();
  $request = $event
    ->getRequest();
  $this
    ->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception
    ->getMessage(), $exception
    ->getFile(), $exception
    ->getLine()));
  $request = $this
    ->duplicateRequest($exception, $request);
  try {
    $response = $event
      ->getKernel()
      ->handle($request, HttpKernelInterface::SUB_REQUEST, false);
  } catch (\Exception $e) {
    $this
      ->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e
      ->getMessage(), $e
      ->getFile(), $e
      ->getLine()), false);
    $wrapper = $e;
    while ($prev = $wrapper
      ->getPrevious()) {
      if ($exception === ($wrapper = $prev)) {
        throw $e;
      }
    }
    $prev = new \ReflectionProperty('Exception', 'previous');
    $prev
      ->setAccessible(true);
    $prev
      ->setValue($wrapper, $exception);
    throw $e;
  }
  $event
    ->setResponse($response);
}