Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExceptionEvent.php

class ExceptionEvent

Allows to create a response for a thrown exception.

Call setResponse() to set the response that will be returned for the current request. The propagation of this event is stopped as soon as a response is set.

You can also call setThrowable() to replace the thrown exception. This exception will be thrown if no response is set during processing of this event.

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Contracts\EventDispatcher\Event implements \Psr\EventDispatcher\StoppableEventInterface
    • class \Symfony\Component\HttpKernel\Event\KernelEvent extends \Symfony\Contracts\EventDispatcher\Event
      • class \Symfony\Component\HttpKernel\Event\RequestEvent extends \Symfony\Component\HttpKernel\Event\KernelEvent
        • class \Symfony\Component\HttpKernel\Event\ExceptionEvent extends \Symfony\Component\HttpKernel\Event\RequestEvent

Expanded class hierarchy of ExceptionEvent

23 files declare their use of ExceptionEvent
AccessDeniedSubscriber.php in core/modules/user/src/EventSubscriber/AccessDeniedSubscriber.php
AuthenticationSubscriber.php in core/lib/Drupal/Core/EventSubscriber/AuthenticationSubscriber.php
CsrfExceptionSubscriber.php in core/lib/Drupal/Core/EventSubscriber/CsrfExceptionSubscriber.php
CustomPageExceptionHtmlSubscriber.php in core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php
DefaultExceptionHtmlSubscriber.php in core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php

... See full list

File

vendor/symfony/http-kernel/Event/ExceptionEvent.php, line 30

Namespace

Symfony\Component\HttpKernel\Event
View source
final class ExceptionEvent extends RequestEvent {
    private \Throwable $throwable;
    private bool $allowCustomResponseCode = false;
    public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, \Throwable $e, bool $isKernelTerminating = false) {
        parent::__construct($kernel, $request, $requestType);
        $this->setThrowable($e);
    }
    public function getThrowable() : \Throwable {
        return $this->throwable;
    }
    
    /**
     * Replaces the thrown exception.
     *
     * This exception will be thrown if no response is set in the event.
     */
    public function setThrowable(\Throwable $exception) : void {
        $this->throwable = $exception;
    }
    
    /**
     * Mark the event as allowing a custom response code.
     */
    public function allowCustomResponseCode() : void {
        $this->allowCustomResponseCode = true;
    }
    
    /**
     * Returns true if the event allows a custom response code.
     */
    public function isAllowingCustomResponseCode() : bool {
        return $this->allowCustomResponseCode;
    }
    public function isKernelTerminating() : bool {
        return $this->isKernelTerminating;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Event::$propagationStopped private property
Event::isPropagationStopped public function Is propagation stopped? Overrides StoppableEventInterface::isPropagationStopped
Event::stopPropagation public function Stops the propagation of the event to further event listeners. 1
ExceptionEvent::$allowCustomResponseCode private property
ExceptionEvent::$throwable private property
ExceptionEvent::allowCustomResponseCode public function Mark the event as allowing a custom response code.
ExceptionEvent::getThrowable public function
ExceptionEvent::isAllowingCustomResponseCode public function Returns true if the event allows a custom response code.
ExceptionEvent::isKernelTerminating public function
ExceptionEvent::setThrowable public function Replaces the thrown exception.
ExceptionEvent::__construct public function Overrides KernelEvent::__construct
KernelEvent::getKernel public function Returns the kernel in which this event was thrown.
KernelEvent::getRequest public function Returns the request the kernel is currently processing.
KernelEvent::getRequestType public function Returns the request type the kernel is currently processing.
KernelEvent::isMainRequest public function Checks if this is the main request.
RequestEvent::$response private property
RequestEvent::getResponse public function Returns the response object.
RequestEvent::hasResponse public function Returns whether a response was set.
RequestEvent::setResponse public function Sets a response and stops event propagation.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal