mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
Add errnoMsg property to ErrnoException
This is used, for example, when you'd want to get a raw error message from the errno number given by the underlying system call/C function, instead of using the msg property, which includes extra (often irrelevant) error information given by the called Phobos function. Previously you would have to use something like this: strerror(e.errno).fromStringz() Example: > catch (ErrnoException e) writeln(e.msg); Cannot open file `filename' in mode `r' (No such file or directory) > catch (ErrnoException e) writeln(e.errnoMsg); No such file or directory
This commit is contained in:
parent
b64bfbf911
commit
04c6590ab8
1 changed files with 5 additions and 1 deletions
|
@ -1632,6 +1632,9 @@ class ErrnoException : Exception
|
|||
/// Operating system error code.
|
||||
final @property uint errno() nothrow pure scope @nogc @safe { return _errno; }
|
||||
private uint _errno;
|
||||
/// Localized error message generated through $(REF strerror_r, core,stdc,string) or $(REF strerror, core,stdc,string).
|
||||
final @property string errnoMsg() nothrow pure scope @nogc @safe { return _errnoMsg; }
|
||||
private string _errnoMsg;
|
||||
/// Constructor which takes an error message. The current global $(REF errno, core,stdc,errno) value is used as error code.
|
||||
this(string msg, string file = null, size_t line = 0) @safe
|
||||
{
|
||||
|
@ -1642,7 +1645,8 @@ class ErrnoException : Exception
|
|||
this(string msg, int errno, string file = null, size_t line = 0) @safe
|
||||
{
|
||||
_errno = errno;
|
||||
super(msg ~ " (" ~ errnoString(errno) ~ ")", file, line);
|
||||
_errnoMsg = errnoString(errno);
|
||||
super(msg ~ " (" ~ errnoMsg ~ ")", file, line);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue