diff --git a/src/Exception/IOException.php b/src/Exception/IOException.php index dd205c0..f07b2ff 100644 --- a/src/Exception/IOException.php +++ b/src/Exception/IOException.php @@ -4,6 +4,7 @@ use Aternos\IO\Interfaces\IOElementInterface; use Exception; +use Throwable; /** * Class IOException @@ -17,10 +18,15 @@ class IOException extends Exception /** * @param string $message * @param IOElementInterface|null $element + * @param Throwable|null $previous */ - public function __construct(string $message = "", protected IOElementInterface|null $element = null) + public function __construct( + string $message = "", + protected IOElementInterface|null $element = null, + ?Throwable $previous = null + ) { - parent::__construct($message); + parent::__construct($message, previous: $previous); } /** @@ -30,4 +36,4 @@ public function getIOElement(): ?IOElementInterface { return $this->element; } -} \ No newline at end of file +} diff --git a/test/Unit/Exception/IOExceptionTest.php b/test/Unit/Exception/IOExceptionTest.php index bf7fee5..09e4f34 100644 --- a/test/Unit/Exception/IOExceptionTest.php +++ b/test/Unit/Exception/IOExceptionTest.php @@ -20,4 +20,11 @@ public function testGetElement(): void $exception = new IOException("test", $element); $this->assertSame($element, $exception->getIOElement()); } -} \ No newline at end of file + + public function testGetPrevious(): void + { + $previous = new \Exception("previous"); + $exception = new IOException("test", null, $previous); + $this->assertSame($previous, $exception->getPrevious()); + } +}