From ab2e8e3f6acc5d5d4393483b661af988a7a29fb2 Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Mon, 3 Feb 2025 17:42:05 +0000
Subject: [PATCH] Issue #3501186 by znerol, smustgrave: Change $previous
 argument for any Exception to \Throwable

---
 .../Plugin/Exception/InvalidPluginDefinitionException.php | 4 ++--
 .../Plugin/Exception/PluginNotFoundException.php          | 4 ++--
 core/lib/Drupal/Core/Database/RowCountException.php       | 2 +-
 core/lib/Drupal/Core/Form/EnforcedResponseException.php   | 4 ++--
 .../Core/Form/Exception/BrokenPostRequestException.php    | 4 ++--
 core/lib/Drupal/Core/Form/FormAjaxException.php           | 4 ++--
 .../Http/Exception/CacheableAccessDeniedHttpException.php | 2 +-
 .../Http/Exception/CacheableBadRequestHttpException.php   | 2 +-
 .../Http/Exception/CacheableConflictHttpException.php     | 2 +-
 .../Core/Http/Exception/CacheableGoneHttpException.php    | 2 +-
 .../Drupal/Core/Http/Exception/CacheableHttpException.php | 2 +-
 .../Exception/CacheableLengthRequiredHttpException.php    | 2 +-
 .../Exception/CacheableMethodNotAllowedHttpException.php  | 2 +-
 .../Exception/CacheableNotAcceptableHttpException.php     | 2 +-
 .../Http/Exception/CacheableNotFoundHttpException.php     | 2 +-
 .../CacheablePreconditionFailedHttpException.php          | 2 +-
 .../CacheablePreconditionRequiredHttpException.php        | 2 +-
 .../CacheableServiceUnavailableHttpException.php          | 2 +-
 .../Exception/CacheableTooManyRequestsHttpException.php   | 2 +-
 .../Http/Exception/CacheableUnauthorizedHttpException.php | 2 +-
 .../CacheableUnprocessableEntityHttpException.php         | 2 +-
 .../CacheableUnsupportedMediaTypeHttpException.php        | 2 +-
 .../Core/Installer/Exception/InstallerException.php       | 4 ++--
 .../Core/ParamConverter/ParamNotConvertedException.php    | 4 ++--
 .../src/Exception/EntityAccessDeniedHttpException.php     | 4 ++--
 .../src/Exception/UnprocessableHttpEntityException.php    | 4 ++--
 .../jsonapi/src/Revisions/VersionNotFoundException.php    | 2 +-
 core/modules/media/src/OEmbed/ProviderException.php       | 4 ++--
 core/modules/media/src/OEmbed/ResourceException.php       | 4 ++--
 core/modules/migrate/src/Audit/AuditException.php         | 4 ++--
 .../migrate/src/Exception/RequirementsException.php       | 4 ++--
 core/modules/migrate/src/MigrateException.php             | 4 ++--
 .../src/Plugin/Exception/BadPluginDefinitionException.php | 4 ++--
 .../Drupal/Tests/Core/Http/CacheableExceptionTest.php     | 8 +++++---
 34 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/core/lib/Drupal/Component/Plugin/Exception/InvalidPluginDefinitionException.php b/core/lib/Drupal/Component/Plugin/Exception/InvalidPluginDefinitionException.php
index 10edb0265e01..cbbf3af9f9de 100644
--- a/core/lib/Drupal/Component/Plugin/Exception/InvalidPluginDefinitionException.php
+++ b/core/lib/Drupal/Component/Plugin/Exception/InvalidPluginDefinitionException.php
@@ -23,12 +23,12 @@ class InvalidPluginDefinitionException extends PluginException {
    *   The exception message.
    * @param int $code
    *   The exception code.
-   * @param \Exception|null $previous
+   * @param \Throwable|null $previous
    *   The previous throwable used for exception chaining.
    *
    * @see \Exception
    */
-  public function __construct($plugin_id, $message = '', $code = 0, ?\Exception $previous = NULL) {
+  public function __construct($plugin_id, $message = '', $code = 0, ?\Throwable $previous = NULL) {
     $this->pluginId = $plugin_id;
     parent::__construct($message, $code, $previous);
   }
diff --git a/core/lib/Drupal/Component/Plugin/Exception/PluginNotFoundException.php b/core/lib/Drupal/Component/Plugin/Exception/PluginNotFoundException.php
index af87c4f8e214..a17724cc97ff 100644
--- a/core/lib/Drupal/Component/Plugin/Exception/PluginNotFoundException.php
+++ b/core/lib/Drupal/Component/Plugin/Exception/PluginNotFoundException.php
@@ -16,12 +16,12 @@ class PluginNotFoundException extends PluginException {
    *   The exception message.
    * @param int $code
    *   The exception code.
-   * @param \Exception|null $previous
+   * @param \Throwable|null $previous
    *   The previous throwable used for exception chaining.
    *
    * @see \Exception
    */
-  public function __construct($plugin_id, $message = '', $code = 0, ?\Exception $previous = NULL) {
+  public function __construct($plugin_id, $message = '', $code = 0, ?\Throwable $previous = NULL) {
     if (empty($message)) {
       $message = sprintf("Plugin ID '%s' was not found.", $plugin_id);
     }
diff --git a/core/lib/Drupal/Core/Database/RowCountException.php b/core/lib/Drupal/Core/Database/RowCountException.php
index c2c2c6a8b271..332abcd0a7aa 100644
--- a/core/lib/Drupal/Core/Database/RowCountException.php
+++ b/core/lib/Drupal/Core/Database/RowCountException.php
@@ -7,7 +7,7 @@
  */
 class RowCountException extends \RuntimeException implements DatabaseException {
 
-  public function __construct($message = '', $code = 0, ?\Exception $previous = NULL) {
+  public function __construct($message = '', $code = 0, ?\Throwable $previous = NULL) {
     if (empty($message)) {
       $message = "rowCount() is supported for DELETE, INSERT, or UPDATE statements performed with structured query builders only, since they would not be portable across database engines otherwise. If the query builders are not sufficient, use a prepareStatement() with an \$allow_row_count argument set to TRUE, execute() the Statement and get the number of matched rows via rowCount().";
     }
diff --git a/core/lib/Drupal/Core/Form/EnforcedResponseException.php b/core/lib/Drupal/Core/Form/EnforcedResponseException.php
index 2df78ee5ba61..b94722ebc483 100644
--- a/core/lib/Drupal/Core/Form/EnforcedResponseException.php
+++ b/core/lib/Drupal/Core/Form/EnforcedResponseException.php
@@ -25,10 +25,10 @@ class EnforcedResponseException extends \Exception {
    *   (optional) The exception message.
    * @param int $code
    *   (optional) A user defined exception code.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   (optional) The previous exception for nested exceptions
    */
-  public function __construct(Response $response, $message = "", $code = 0, ?\Exception $previous = NULL) {
+  public function __construct(Response $response, $message = "", $code = 0, ?\Throwable $previous = NULL) {
     parent::__construct($message, $code, $previous);
 
     $this->response = $response;
diff --git a/core/lib/Drupal/Core/Form/Exception/BrokenPostRequestException.php b/core/lib/Drupal/Core/Form/Exception/BrokenPostRequestException.php
index 39e53d038d3f..501b1661a1af 100644
--- a/core/lib/Drupal/Core/Form/Exception/BrokenPostRequestException.php
+++ b/core/lib/Drupal/Core/Form/Exception/BrokenPostRequestException.php
@@ -25,12 +25,12 @@ class BrokenPostRequestException extends BadRequestHttpException {
    *   The size of the maximum upload size in bytes.
    * @param string $message
    *   The internal exception message.
-   * @param \Exception|null $previous
+   * @param \Throwable|null $previous
    *   The previous exception.
    * @param int $code
    *   The internal exception code.
    */
-  public function __construct(int $max_upload_size, string $message = '', ?\Exception $previous = NULL, int $code = 0) {
+  public function __construct(int $max_upload_size, string $message = '', ?\Throwable $previous = NULL, int $code = 0) {
     parent::__construct($message, $previous, $code);
 
     $this->size = $max_upload_size;
diff --git a/core/lib/Drupal/Core/Form/FormAjaxException.php b/core/lib/Drupal/Core/Form/FormAjaxException.php
index 5393c92f2f5c..6ff8a1496e9b 100644
--- a/core/lib/Drupal/Core/Form/FormAjaxException.php
+++ b/core/lib/Drupal/Core/Form/FormAjaxException.php
@@ -32,10 +32,10 @@ class FormAjaxException extends \Exception {
    *   (optional) The exception message.
    * @param int $code
    *   (optional) A user defined exception code.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   (optional) The previous exception for nested exceptions.
    */
-  public function __construct(array $form, FormStateInterface $form_state, $message = "", $code = 0, ?\Exception $previous = NULL) {
+  public function __construct(array $form, FormStateInterface $form_state, $message = "", $code = 0, ?\Throwable $previous = NULL) {
     parent::__construct($message, $code, $previous);
     $this->form = $form;
     $this->formState = $form_state;
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableAccessDeniedHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableAccessDeniedHttpException.php
index 85d4b1842728..13921e85b837 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableAccessDeniedHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableAccessDeniedHttpException.php
@@ -16,7 +16,7 @@ class CacheableAccessDeniedHttpException extends AccessDeniedHttpException imple
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableBadRequestHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableBadRequestHttpException.php
index 92ebd361c6ba..1e682b9bec9a 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableBadRequestHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableBadRequestHttpException.php
@@ -16,7 +16,7 @@ class CacheableBadRequestHttpException extends BadRequestHttpException implement
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableConflictHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableConflictHttpException.php
index 7580ed7e1ede..caf7f3fc536f 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableConflictHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableConflictHttpException.php
@@ -16,7 +16,7 @@ class CacheableConflictHttpException extends ConflictHttpException implements Ca
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableGoneHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableGoneHttpException.php
index dc8d29a66561..5e04615bcdd7 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableGoneHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableGoneHttpException.php
@@ -16,7 +16,7 @@ class CacheableGoneHttpException extends GoneHttpException implements CacheableD
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableHttpException.php
index 2710c9f6b8f6..59030694eac8 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableHttpException.php
@@ -16,7 +16,7 @@ class CacheableHttpException extends HttpException implements CacheableDependenc
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $statusCode = 0, $message = '', ?\Exception $previous = NULL, array $headers = [], $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $statusCode = 0, $message = '', ?\Throwable $previous = NULL, array $headers = [], $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($statusCode, $message, $previous, $headers, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableLengthRequiredHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableLengthRequiredHttpException.php
index b0004d943b22..231d4e87c8f7 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableLengthRequiredHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableLengthRequiredHttpException.php
@@ -16,7 +16,7 @@ class CacheableLengthRequiredHttpException extends LengthRequiredHttpException i
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableMethodNotAllowedHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableMethodNotAllowedHttpException.php
index 26f967ce3141..7eb3f41693c7 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableMethodNotAllowedHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableMethodNotAllowedHttpException.php
@@ -16,7 +16,7 @@ class CacheableMethodNotAllowedHttpException extends MethodNotAllowedHttpExcepti
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, array $allow, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, array $allow, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($allow, $message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableNotAcceptableHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableNotAcceptableHttpException.php
index 430db51fe55d..b03eb8063067 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableNotAcceptableHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableNotAcceptableHttpException.php
@@ -16,7 +16,7 @@ class CacheableNotAcceptableHttpException extends NotAcceptableHttpException imp
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableNotFoundHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableNotFoundHttpException.php
index 9149df14957b..d7cdc28f83ca 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableNotFoundHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableNotFoundHttpException.php
@@ -16,7 +16,7 @@ class CacheableNotFoundHttpException extends NotFoundHttpException implements Ca
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionFailedHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionFailedHttpException.php
index 69d07debe6e9..57eb781ac81b 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionFailedHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionFailedHttpException.php
@@ -16,7 +16,7 @@ class CacheablePreconditionFailedHttpException extends PreconditionFailedHttpExc
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionRequiredHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionRequiredHttpException.php
index d86273fa8c0c..f1301354819e 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionRequiredHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheablePreconditionRequiredHttpException.php
@@ -16,7 +16,7 @@ class CacheablePreconditionRequiredHttpException extends PreconditionRequiredHtt
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableServiceUnavailableHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableServiceUnavailableHttpException.php
index 8a7eeea2e26b..3f200ec432b8 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableServiceUnavailableHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableServiceUnavailableHttpException.php
@@ -16,7 +16,7 @@ class CacheableServiceUnavailableHttpException extends ServiceUnavailableHttpExc
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $retryAfter = NULL, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $retryAfter = NULL, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($retryAfter, $message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableTooManyRequestsHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableTooManyRequestsHttpException.php
index 89f16fd8f164..4b3d5138b644 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableTooManyRequestsHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableTooManyRequestsHttpException.php
@@ -16,7 +16,7 @@ class CacheableTooManyRequestsHttpException extends TooManyRequestsHttpException
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $retryAfter = NULL, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $retryAfter = NULL, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($retryAfter, $message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableUnauthorizedHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableUnauthorizedHttpException.php
index 43f7ef587f2f..7429c44a79de 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableUnauthorizedHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableUnauthorizedHttpException.php
@@ -16,7 +16,7 @@ class CacheableUnauthorizedHttpException extends UnauthorizedHttpException imple
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $challenge, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $challenge, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($challenge, $message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableUnprocessableEntityHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableUnprocessableEntityHttpException.php
index 53208360d3da..2f6562d821b2 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableUnprocessableEntityHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableUnprocessableEntityHttpException.php
@@ -16,7 +16,7 @@ class CacheableUnprocessableEntityHttpException extends UnprocessableEntityHttpE
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Http/Exception/CacheableUnsupportedMediaTypeHttpException.php b/core/lib/Drupal/Core/Http/Exception/CacheableUnsupportedMediaTypeHttpException.php
index a1a2ac5a466d..0efda3b6bb18 100644
--- a/core/lib/Drupal/Core/Http/Exception/CacheableUnsupportedMediaTypeHttpException.php
+++ b/core/lib/Drupal/Core/Http/Exception/CacheableUnsupportedMediaTypeHttpException.php
@@ -16,7 +16,7 @@ class CacheableUnsupportedMediaTypeHttpException extends UnsupportedMediaTypeHtt
   /**
    * {@inheritdoc}
    */
-  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Exception $previous = NULL, $code = 0) {
+  public function __construct(CacheableDependencyInterface $cacheability, $message = '', ?\Throwable $previous = NULL, $code = 0) {
     $this->setCacheability($cacheability);
     parent::__construct($message, $previous, $code);
   }
diff --git a/core/lib/Drupal/Core/Installer/Exception/InstallerException.php b/core/lib/Drupal/Core/Installer/Exception/InstallerException.php
index beb0e9dc535f..b0e245227f4a 100644
--- a/core/lib/Drupal/Core/Installer/Exception/InstallerException.php
+++ b/core/lib/Drupal/Core/Installer/Exception/InstallerException.php
@@ -26,10 +26,10 @@ class InstallerException extends \RuntimeException {
    *   (optional) The page title. Defaults to 'Error'.
    * @param int $code
    *   (optional) The exception code. Defaults to 0.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   (optional) A previous exception.
    */
-  public function __construct($message, $title = 'Error', $code = 0, ?\Exception $previous = NULL) {
+  public function __construct($message, $title = 'Error', $code = 0, ?\Throwable $previous = NULL) {
     parent::__construct($message, $code, $previous);
     $this->title = $title;
   }
diff --git a/core/lib/Drupal/Core/ParamConverter/ParamNotConvertedException.php b/core/lib/Drupal/Core/ParamConverter/ParamNotConvertedException.php
index ded46faeb76d..19e8b307ac3b 100644
--- a/core/lib/Drupal/Core/ParamConverter/ParamNotConvertedException.php
+++ b/core/lib/Drupal/Core/ParamConverter/ParamNotConvertedException.php
@@ -28,14 +28,14 @@ class ParamNotConvertedException extends \Exception {
    *   The Exception message to throw.
    * @param int $code
    *   The Exception code.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   The previous exception used for the exception chaining.
    * @param string $route_name
    *   The route name that was not converted.
    * @param array $raw_parameters
    *   The raw parameters that were not converted.
    */
-  public function __construct($message = "", $code = 0, ?\Exception $previous = NULL, $route_name = "", array $raw_parameters = []) {
+  public function __construct($message = "", $code = 0, ?\Throwable $previous = NULL, $route_name = "", array $raw_parameters = []) {
     parent::__construct($message, $code, $previous);
     $this->routeName = $route_name;
     $this->rawParameters = $raw_parameters;
diff --git a/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php b/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php
index b2b55c09291b..8ee54bbae5a1 100644
--- a/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php
+++ b/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php
@@ -53,12 +53,12 @@ class EntityAccessDeniedHttpException extends CacheableAccessDeniedHttpException
    * @param string $relationship_field
    *   (Optional) A relationship field name if access was denied because the
    *   user does not have permission to view an entity's relationship field.
-   * @param \Exception|null $previous
+   * @param \Throwable|null $previous
    *   The previous exception.
    * @param int $code
    *   The code.
    */
-  public function __construct($entity, AccessResultInterface $entity_access, $pointer, $message = 'The current user is not allowed to GET the selected resource.', $relationship_field = NULL, ?\Exception $previous = NULL, $code = 0) {
+  public function __construct($entity, AccessResultInterface $entity_access, $pointer, $message = 'The current user is not allowed to GET the selected resource.', $relationship_field = NULL, ?\Throwable $previous = NULL, $code = 0) {
     assert(is_null($entity) || $entity instanceof EntityInterface);
     parent::__construct(CacheableMetadata::createFromObject($entity_access), $message, $previous, $code);
     $error = [
diff --git a/core/modules/jsonapi/src/Exception/UnprocessableHttpEntityException.php b/core/modules/jsonapi/src/Exception/UnprocessableHttpEntityException.php
index 4dce06e1e63d..566833a0432a 100644
--- a/core/modules/jsonapi/src/Exception/UnprocessableHttpEntityException.php
+++ b/core/modules/jsonapi/src/Exception/UnprocessableHttpEntityException.php
@@ -35,14 +35,14 @@ class UnprocessableHttpEntityException extends HttpException {
   /**
    * UnprocessableHttpEntityException constructor.
    *
-   * @param \Exception|null $previous
+   * @param \Throwable|null $previous
    *   The pervious error, if any, associated with the request.
    * @param array $headers
    *   The headers associated with the request.
    * @param int $code
    *   The HTTP status code associated with the request. Defaults to zero.
    */
-  public function __construct(?\Exception $previous = NULL, array $headers = [], $code = 0) {
+  public function __construct(?\Throwable $previous = NULL, array $headers = [], $code = 0) {
     parent::__construct(422, "Unprocessable Entity: validation failed.", $previous, $headers, $code);
   }
 
diff --git a/core/modules/jsonapi/src/Revisions/VersionNotFoundException.php b/core/modules/jsonapi/src/Revisions/VersionNotFoundException.php
index 8e3a680e4fc3..0b5abe21b1b5 100644
--- a/core/modules/jsonapi/src/Revisions/VersionNotFoundException.php
+++ b/core/modules/jsonapi/src/Revisions/VersionNotFoundException.php
@@ -16,7 +16,7 @@ class VersionNotFoundException extends \InvalidArgumentException {
   /**
    * {@inheritdoc}
    */
-  public function __construct($message = '', $code = 0, ?\Exception $previous = NULL) {
+  public function __construct($message = '', $code = 0, ?\Throwable $previous = NULL) {
     parent::__construct(!is_null($message) ? $message : 'The identified version could not be found.', $code, $previous);
   }
 
diff --git a/core/modules/media/src/OEmbed/ProviderException.php b/core/modules/media/src/OEmbed/ProviderException.php
index 8fa6100c389e..2774e484a543 100644
--- a/core/modules/media/src/OEmbed/ProviderException.php
+++ b/core/modules/media/src/OEmbed/ProviderException.php
@@ -28,10 +28,10 @@ class ProviderException extends \Exception {
    *   if available, or '<unknown>' if not.
    * @param \Drupal\media\OEmbed\Provider $provider
    *   (optional) The provider information.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   (optional) The previous exception, if any.
    */
-  public function __construct($message, ?Provider $provider = NULL, ?\Exception $previous = NULL) {
+  public function __construct($message, ?Provider $provider = NULL, ?\Throwable $previous = NULL) {
     $this->provider = $provider;
     $message = str_replace('@name', $provider ? $provider->getName() : '<unknown>', $message);
     parent::__construct($message, 0, $previous);
diff --git a/core/modules/media/src/OEmbed/ResourceException.php b/core/modules/media/src/OEmbed/ResourceException.php
index 7ac8dcf59748..f8767025d631 100644
--- a/core/modules/media/src/OEmbed/ResourceException.php
+++ b/core/modules/media/src/OEmbed/ResourceException.php
@@ -35,10 +35,10 @@ class ResourceException extends \Exception {
    *   URL.
    * @param array $data
    *   (optional) The raw resource data, if available.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   (optional) The previous exception, if any.
    */
-  public function __construct($message, $url, array $data = [], ?\Exception $previous = NULL) {
+  public function __construct($message, $url, array $data = [], ?\Throwable $previous = NULL) {
     $this->url = $url;
     $this->data = $data;
     parent::__construct($message, 0, $previous);
diff --git a/core/modules/migrate/src/Audit/AuditException.php b/core/modules/migrate/src/Audit/AuditException.php
index 1fbeb2ea3991..a23ce2c49fe4 100644
--- a/core/modules/migrate/src/Audit/AuditException.php
+++ b/core/modules/migrate/src/Audit/AuditException.php
@@ -16,10 +16,10 @@ class AuditException extends \RuntimeException {
    *   The migration that caused the exception.
    * @param string $message
    *   The reason the audit failed.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   (optional) The previous exception.
    */
-  public function __construct(MigrationInterface $migration, $message, ?\Exception $previous = NULL) {
+  public function __construct(MigrationInterface $migration, $message, ?\Throwable $previous = NULL) {
     $message = sprintf('Cannot audit migration %s: %s', $migration->id(), $message);
     parent::__construct($message, 0, $previous);
   }
diff --git a/core/modules/migrate/src/Exception/RequirementsException.php b/core/modules/migrate/src/Exception/RequirementsException.php
index 9958209c3e3d..702f1361db13 100644
--- a/core/modules/migrate/src/Exception/RequirementsException.php
+++ b/core/modules/migrate/src/Exception/RequirementsException.php
@@ -25,10 +25,10 @@ class RequirementsException extends \RuntimeException {
    *   (optional) The missing requirements.
    * @param int $code
    *   (optional) The Exception code.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   (optional) The previous exception used for the exception chaining.
    */
-  public function __construct($message = "", array $requirements = [], $code = 0, ?\Exception $previous = NULL) {
+  public function __construct($message = "", array $requirements = [], $code = 0, ?\Throwable $previous = NULL) {
     parent::__construct($message, $code, $previous);
 
     $this->requirements = $requirements;
diff --git a/core/modules/migrate/src/MigrateException.php b/core/modules/migrate/src/MigrateException.php
index f1132e5e7d02..6b7e6d95779e 100644
--- a/core/modules/migrate/src/MigrateException.php
+++ b/core/modules/migrate/src/MigrateException.php
@@ -39,7 +39,7 @@ class MigrateException extends \Exception {
    *   The message for the exception.
    * @param int $code
    *   The Exception code.
-   * @param \Exception $previous
+   * @param \Throwable $previous
    *   The previous exception used for the exception chaining.
    * @param int $level
    *   The level of the error, a Migration::MESSAGE_* constant.
@@ -47,7 +47,7 @@ class MigrateException extends \Exception {
    *   The status of the item for the map table, a MigrateMap::STATUS_*
    *   constant.
    */
-  public function __construct($message = '', $code = 0, ?\Exception $previous = NULL, $level = MigrationInterface::MESSAGE_ERROR, $status = MigrateIdMapInterface::STATUS_FAILED) {
+  public function __construct($message = '', $code = 0, ?\Throwable $previous = NULL, $level = MigrationInterface::MESSAGE_ERROR, $status = MigrateIdMapInterface::STATUS_FAILED) {
     $this->level = $level;
     $this->status = $status;
     parent::__construct($message);
diff --git a/core/modules/migrate/src/Plugin/Exception/BadPluginDefinitionException.php b/core/modules/migrate/src/Plugin/Exception/BadPluginDefinitionException.php
index deb92b858c18..d5b25b445103 100644
--- a/core/modules/migrate/src/Plugin/Exception/BadPluginDefinitionException.php
+++ b/core/modules/migrate/src/Plugin/Exception/BadPluginDefinitionException.php
@@ -18,12 +18,12 @@ class BadPluginDefinitionException extends InvalidPluginDefinitionException {
    *   The name of the property that is missing from the plugin.
    * @param int $code
    *   (optional) The exception code. Defaults to 0.
-   * @param \Exception|null $previous
+   * @param \Throwable|null $previous
    *   The previous throwable used for exception chaining.
    *
    * @see \Exception
    */
-  public function __construct($plugin_id, $property, $code = 0, ?\Exception $previous = NULL) {
+  public function __construct($plugin_id, $property, $code = 0, ?\Throwable $previous = NULL) {
     $message = sprintf('The %s plugin must define the %s property.', $plugin_id, $property);
     parent::__construct($plugin_id, $message, $code, $previous);
   }
diff --git a/core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php b/core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php
index 91587fd52031..ead670c04128 100644
--- a/core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php
+++ b/core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php
@@ -46,16 +46,18 @@ public function testCacheableHttpException(): void {
   public function testExceptions($status_code, $class, $argument = NULL, $expected_headers = []): void {
     $cacheable_metadata = (new CacheableMetadata())->setCacheContexts(['route']);
     $message = "$class test message";
+    $previous = new class('Error of PHP 7+') extends \Error {};
     if ($argument) {
-      $exception = new $class($cacheable_metadata, $argument, $message, NULL, 123);
+      $exception = new $class($cacheable_metadata, $argument, $message, $previous, 123);
     }
     else {
-      $exception = new $class($cacheable_metadata, $message, NULL, 123);
+      $exception = new $class($cacheable_metadata, $message, $previous, 123);
     }
     $this->assertSame(['route'], $exception->getCacheContexts());
     $this->assertSame($message, $exception->getMessage());
     $this->assertSame($status_code, $exception->getStatusCode());
     $this->assertSame($expected_headers, $exception->getHeaders());
+    $this->assertSame($previous, $exception->getPrevious());
     $this->assertSame(123, $exception->getCode());
   }
 
@@ -65,7 +67,7 @@ public static function providerTestExceptions() {
       [401, CacheableUnauthorizedHttpException::class, 'test challenge', ['WWW-Authenticate' => 'test challenge']],
       [403, CacheableAccessDeniedHttpException::class],
       [404, CacheableNotFoundHttpException::class],
-      [405, CacheableMethodNotAllowedHttpException::Class, ['POST', 'PUT'], ['Allow' => 'POST, PUT']],
+      [405, CacheableMethodNotAllowedHttpException::class, ['POST', 'PUT'], ['Allow' => 'POST, PUT']],
       [406, CacheableNotAcceptableHttpException::class],
       [409, CacheableConflictHttpException::class],
       [410, CacheableGoneHttpException::class],
-- 
GitLab