Skip to content

Commit 027ffa3

Browse files
authored
Merge pull request #3 from KurtThiemann/io-exception-previous
Allow passing previous exception to IOException constructor
2 parents 1884a98 + 01b31f2 commit 027ffa3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Exception/IOException.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Aternos\IO\Interfaces\IOElementInterface;
66
use Exception;
7+
use Throwable;
78

89
/**
910
* Class IOException
@@ -17,10 +18,15 @@ class IOException extends Exception
1718
/**
1819
* @param string $message
1920
* @param IOElementInterface|null $element
21+
* @param Throwable|null $previous
2022
*/
21-
public function __construct(string $message = "", protected IOElementInterface|null $element = null)
23+
public function __construct(
24+
string $message = "",
25+
protected IOElementInterface|null $element = null,
26+
?Throwable $previous = null
27+
)
2228
{
23-
parent::__construct($message);
29+
parent::__construct($message, previous: $previous);
2430
}
2531

2632
/**
@@ -30,4 +36,4 @@ public function getIOElement(): ?IOElementInterface
3036
{
3137
return $this->element;
3238
}
33-
}
39+
}

test/Unit/Exception/IOExceptionTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ public function testGetElement(): void
2020
$exception = new IOException("test", $element);
2121
$this->assertSame($element, $exception->getIOElement());
2222
}
23-
}
23+
24+
public function testGetPrevious(): void
25+
{
26+
$previous = new \Exception("previous");
27+
$exception = new IOException("test", null, $previous);
28+
$this->assertSame($previous, $exception->getPrevious());
29+
}
30+
}

0 commit comments

Comments
 (0)