code: private function renderErrorScreenByException(GetResponseForExceptionEvent $event): void
      {
          $exception = $event->getException();
          $statusCode = $this->getStatusCodeForException($exception);
          $template = null;
  
          $this->logException($exception);
  
          // Look for a template
          do {
              if ($exception instanceof \Exception) {
                  $template = $this->getTemplateForException($exception);
              }
          } while (null === $template && null !== ($exception = $exception->getPrevious()));
  
          $this->renderTemplate($template ?: 'error', $statusCode, $event);
      }
docs: Checks the exception chain for a known exception.