Skip to content

Commit

Permalink
Merge pull request #5124 from tomerfiliba/ErrnoException-ctor
Browse files Browse the repository at this point in the history
ErrnoException: add a ctor overload that takes errno as an argument
  • Loading branch information
JackStouffer committed Feb 14, 2017
2 parents 70ea6a1 + 66a90c5 commit 2395725
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions std/exception.d
Expand Up @@ -1457,6 +1457,10 @@ class ErrnoException : Exception
this(string msg, string file = null, size_t line = 0) @trusted
{
import core.stdc.errno : errno;
this(msg, errno, file, line);
}
this(string msg, int errno, string file = null, size_t line = 0) @trusted
{
import core.stdc.string : strlen;

_errno = errno;
Expand All @@ -1473,6 +1477,25 @@ class ErrnoException : Exception
}
super(msg ~ " (" ~ s[0..s.strlen].idup ~ ")", file, line);
}

unittest
{
import core.stdc.errno : errno, EAGAIN;

auto old = errno;
scope(exit) errno = old;

errno = EAGAIN;
auto ex = new ErrnoException("oh no");
assert (ex.errno == EAGAIN);
}

unittest
{
import core.stdc.errno : EAGAIN;
auto ex = new ErrnoException("oh no", EAGAIN);
assert (ex.errno == EAGAIN);
}
}

/++
Expand Down

0 comments on commit 2395725

Please sign in to comment.