From b20a8df00cecd426b8283a5719533255c7073658 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Wed, 3 Jan 2024 15:27:36 +0100 Subject: [PATCH] Add exception handling to Singleton trait --- src/Traits/Singleton.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Traits/Singleton.php b/src/Traits/Singleton.php index 4c98aac..1157a32 100644 --- a/src/Traits/Singleton.php +++ b/src/Traits/Singleton.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace OCC\Basics\Traits; +use Exception; use LogicException; /** @@ -45,11 +46,17 @@ trait Singleton * @param mixed ...$args Constructor parameters * * @return static The singleton instance + * + * @throws Exception */ final public static function getInstance(mixed ...$args): static { if (!isset(static::$singleton[static::class])) { - static::$singleton[static::class] = new static(...$args); + try { + static::$singleton[static::class] = new static(...$args); + } catch (Exception $exception) { + throw $exception; + } } return static::$singleton[static::class]; }