From 07f2fea6c1ddf032d17dd327fc3c573b73e45ef2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 10 Jun 2024 14:42:43 +0200 Subject: [PATCH] Catch `\Throwable` instead of `\Exception` `\Throwable` is the base for all errors and exceptions since PHP 7. --- src/DeferredText.php | 4 ++-- src/Form.php | 6 +++--- src/FormattedString.php | 4 ++-- src/HtmlDocument.php | 4 ++-- src/Text.php | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DeferredText.php b/src/DeferredText.php index 2d308f16..aa5205e5 100644 --- a/src/DeferredText.php +++ b/src/DeferredText.php @@ -2,7 +2,7 @@ namespace ipl\Html; -use Exception; +use Throwable; /** * Text node where content creation is deferred until rendering @@ -96,7 +96,7 @@ public function __toString() { try { return $this->render(); - } catch (Exception $e) { + } catch (Throwable $e) { return Error::render($e); } } diff --git a/src/Form.php b/src/Form.php index a7360c7d..ab13dd56 100644 --- a/src/Form.php +++ b/src/Form.php @@ -2,12 +2,12 @@ namespace ipl\Html; -use Exception; use ipl\Html\Contract\FormElement; use ipl\Html\Contract\FormSubmitElement; use ipl\Html\FormElement\FormElements; use ipl\Stdlib\Messages; use Psr\Http\Message\ServerRequestInterface; +use Throwable; class Form extends BaseHtmlElement { @@ -237,7 +237,7 @@ public function handleRequest(ServerRequestInterface $request) $this->emit(Form::ON_SENT, [$this]); $this->onSuccess(); $this->emitOnce(Form::ON_SUCCESS, [$this]); - } catch (Exception $e) { + } catch (Throwable $e) { $this->addMessage($e); $this->onError(); $this->emit(Form::ON_ERROR, [$e, $this]); @@ -363,7 +363,7 @@ protected function onError() { $errors = Html::tag('ul', ['class' => 'errors']); foreach ($this->getMessages() as $message) { - if ($message instanceof Exception) { + if ($message instanceof Throwable) { $message = $message->getMessage(); } diff --git a/src/FormattedString.php b/src/FormattedString.php index 1ef9b5b8..a4e5256f 100644 --- a/src/FormattedString.php +++ b/src/FormattedString.php @@ -2,8 +2,8 @@ namespace ipl\Html; -use Exception; use InvalidArgumentException; +use Throwable; use function ipl\Stdlib\get_php_type; @@ -86,7 +86,7 @@ public function __toString() { try { return $this->render(); - } catch (Exception $e) { + } catch (Throwable $e) { return Error::render($e); } } diff --git a/src/HtmlDocument.php b/src/HtmlDocument.php index e4e977e7..d9a153a8 100644 --- a/src/HtmlDocument.php +++ b/src/HtmlDocument.php @@ -3,11 +3,11 @@ namespace ipl\Html; use Countable; -use Exception; use InvalidArgumentException; use ipl\Html\Contract\Wrappable; use ipl\Stdlib\Events; use RuntimeException; +use Throwable; /** * HTML document @@ -418,7 +418,7 @@ public function __toString() { try { return $this->render(); - } catch (Exception $e) { + } catch (Throwable $e) { return Error::render($e); } } diff --git a/src/Text.php b/src/Text.php index 710e3d91..946bbb17 100644 --- a/src/Text.php +++ b/src/Text.php @@ -2,7 +2,7 @@ namespace ipl\Html; -use Exception; +use Throwable; /** * A text node @@ -100,7 +100,7 @@ public function __toString() { try { return $this->render(); - } catch (Exception $e) { + } catch (Throwable $e) { return Error::render($e); } }