Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrnoException: add a ctor overload that takes errno as an argument #5124

Merged
merged 1 commit into from Feb 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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