Skip to content

Commit 2395725

Browse files
authored
Merge pull request #5124 from tomerfiliba/ErrnoException-ctor
ErrnoException: add a ctor overload that takes errno as an argument
2 parents 70ea6a1 + 66a90c5 commit 2395725

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

std/exception.d

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,10 @@ class ErrnoException : Exception
14571457
this(string msg, string file = null, size_t line = 0) @trusted
14581458
{
14591459
import core.stdc.errno : errno;
1460+
this(msg, errno, file, line);
1461+
}
1462+
this(string msg, int errno, string file = null, size_t line = 0) @trusted
1463+
{
14601464
import core.stdc.string : strlen;
14611465

14621466
_errno = errno;
@@ -1473,6 +1477,25 @@ class ErrnoException : Exception
14731477
}
14741478
super(msg ~ " (" ~ s[0..s.strlen].idup ~ ")", file, line);
14751479
}
1480+
1481+
unittest
1482+
{
1483+
import core.stdc.errno : errno, EAGAIN;
1484+
1485+
auto old = errno;
1486+
scope(exit) errno = old;
1487+
1488+
errno = EAGAIN;
1489+
auto ex = new ErrnoException("oh no");
1490+
assert (ex.errno == EAGAIN);
1491+
}
1492+
1493+
unittest
1494+
{
1495+
import core.stdc.errno : EAGAIN;
1496+
auto ex = new ErrnoException("oh no", EAGAIN);
1497+
assert (ex.errno == EAGAIN);
1498+
}
14761499
}
14771500

14781501
/++

0 commit comments

Comments
 (0)