1. 8.5.x vendor/symfony/http-kernel/KernelEvents.php KernelEvents::EXCEPTION
  2. 8.0.x vendor/symfony/http-kernel/KernelEvents.php KernelEvents::EXCEPTION
  3. 8.1.x vendor/symfony/http-kernel/KernelEvents.php KernelEvents::EXCEPTION
  4. 8.2.x vendor/symfony/http-kernel/KernelEvents.php KernelEvents::EXCEPTION
  5. 8.3.x vendor/symfony/http-kernel/KernelEvents.php KernelEvents::EXCEPTION
  6. 8.4.x vendor/symfony/http-kernel/KernelEvents.php KernelEvents::EXCEPTION
  7. 8.6.x vendor/symfony/http-kernel/KernelEvents.php KernelEvents::EXCEPTION

The EXCEPTION event occurs when an uncaught exception appears.

This event allows you to create a response for a thrown exception or to modify the thrown exception. The event listener method receives a Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent instance.

Related topics

File

vendor/symfony/http-kernel/KernelEvents.php, line 48

Class

KernelEvents
Contains all events thrown in the HttpKernel component.

Namespace

Symfony\Component\HttpKernel

Code

const EXCEPTION = 'kernel.exception';

Comments

taggartj’s picture

Say you have a bad scary error and you need to keep people well away form this area untill you can fix / patch it
create the base event subscriber with drupal console use kernel.exception and, add in the current_route_match service

Basic idea make sure its where the error is ( hence current_route_match) and check the execption type
then redirect them some where safe.

/**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events['kernel.exception'] = ['handleWorkbenchSqlException'];
    return $events;
  }

 public function handleWorkbenchSqlException(Event $event) {
    $exception = $event->getException();
    if ($exception instanceof DatabaseExceptionWrapper) {
      $file = $exception->getFile();
      $match = $this->currentRouteMatch->getRouteName();
      $allowed = [
        'view.workbench.page_1',
        'workbench.content',
      ];
      if (strpos($file, 'views/query/Sql.php') !== FALSE && in_array($match, $allowed)) {
        $response = new RedirectResponse('/user');
        $response->send();
        drupal_set_message(t('No content in workbench yet please import or create some.'), 'status', TRUE);
      }
    }
  }