Re: ErrnoException

2016-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/1/16 12:44 AM, Mike Parker wrote:

On Tuesday, 1 March 2016 at 01:31:56 UTC, Jirka wrote:



Ok, that would throw some OOM exception instead so I wouldn't need to
bother with it, is there something else in the GC that would override
it during class instance allocation? I am finding it weird that
ErrnoException doesn't let you specify the errno value explicitly, you
usually check it in your code anyway (e.g. for EINTR and repeat the
operation and not throw this error).


An additional constructor that accepts and errno value sounds like a
good potential PR.


Yes, please file an enhancement request.

-Steve


Re: ErrnoException

2016-02-29 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 1 March 2016 at 01:31:56 UTC, Jirka wrote:



Ok, that would throw some OOM exception instead so I wouldn't 
need to bother with it, is there something else in the GC that 
would override it during class instance allocation? I am 
finding it weird that ErrnoException doesn't let you specify 
the errno value explicitly, you usually check it in your code 
anyway (e.g. for EINTR and repeat the operation and not throw 
this error).


An additional constructor that accepts and errno value sounds 
like a good potential PR.


Re: ErrnoException

2016-02-29 Thread Jirka via Digitalmars-d-learn

On Monday, 29 February 2016 at 23:41:51 UTC, Chris Wright wrote:

On Mon, 29 Feb 2016 21:55:49 +, Jirka wrote:

Yes, that I understand, but the "new" operator can lead to 
other system calls (?), could they overwrite it?


Yes. Most obviously, the GC uses malloc, which will set errno 
to ENOMEM on failure.


Ok, that would throw some OOM exception instead so I wouldn't 
need to bother with it, is there something else in the GC that 
would override it during class instance allocation? I am finding 
it weird that ErrnoException doesn't let you specify the errno 
value explicitly, you usually check it in your code anyway (e.g. 
for EINTR and repeat the operation and not throw this error).


Re: ErrnoException

2016-02-29 Thread Chris Wright via Digitalmars-d-learn
On Mon, 29 Feb 2016 21:55:49 +, Jirka wrote:

> Yes, that I understand, but the "new" operator can lead to other system
> calls (?), could they overwrite it?

Yes. Most obviously, the GC uses malloc, which will set errno to ENOMEM 
on failure.


Re: ErrnoException

2016-02-29 Thread Jirka via Digitalmars-d-learn

On Sunday, 28 February 2016 at 14:59:22 UTC, Mike Parker wrote:

On Sunday, 28 February 2016 at 13:10:20 UTC, Jirka wrote:
I have a question about ErrnoException. When I throw it (throw 
new ErrnoException()), won't it overwrite the errno value 
before it can capture it?


Its constructor [1] simply fetches the current errno and gets 
an error message from it.


[1] 
https://github.com/D-Programming-Language/phobos/blob/master/std/exception.d#L1491


Yes, that I understand, but the "new" operator can lead to other 
system calls (?), could they overwrite it?


Re: ErrnoException

2016-02-28 Thread Mike Parker via Digitalmars-d-learn

On Sunday, 28 February 2016 at 13:10:20 UTC, Jirka wrote:
I have a question about ErrnoException. When I throw it (throw 
new ErrnoException()), won't it overwrite the errno value 
before it can capture it?


Its constructor [1] simply fetches the current errno and gets an 
error message from it.


[1] 
https://github.com/D-Programming-Language/phobos/blob/master/std/exception.d#L1491


ErrnoException

2016-02-28 Thread Jirka via Digitalmars-d-learn
I have a question about ErrnoException. When I throw it (throw 
new ErrnoException()), won't it overwrite the errno value before 
it can capture it?


Re: ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Thans guys!

wenforce not sutable - error code is lost.
may be, i will use modified wenforce, wich throws ErrnoException.


Re: ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Ha, i found
std.windows.syserror: WindowsException, wenforce;


Re: ErrnoException in Windows

2015-03-01 Thread ketmar via Digitalmars-d-learn
On Sun, 01 Mar 2015 16:39:27 +, novice2 wrote:

 Could you, please, help me to understand, why code:

'cause winapi functions never sets `errno`. `errno` is a libc feature, 
and winapi knows nothing about libc. besides, `GetLastError()` is not 
required to return correct errno codes.

so you have to either use libc funcions, or translate `GetLastError()` 
codes to errno manually.

signature.asc
Description: PGP signature


ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Could you, please, help me to understand, why code:


import std.c.windows.windows;
import std.exception: ErrnoException;
import std.stdio: writefln;
import std.string: toStringz;

void main ()
{
  CreateFileA(toStringz(nonexisting file name), GENERIC_READ, 
FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 
null);

  auto ex = new ErrnoException(CreateFileA);
  writefln(ex.errno=%d, ex.msg=%s, lasterror=%d, ex.errno, 
ex.msg, GetLastError());

}


prints:
ex.errno=0, ex.msg=CreateFileA (No error), lasterror=2

I wanted it will be:
ex.errno=2, ex.msg=CreateFileA (File not found), lasterror=2


Re: ErrnoException in Windows

2015-03-01 Thread Vladimir Panteleev via Digitalmars-d-learn

On Sunday, 1 March 2015 at 16:39:29 UTC, novice2 wrote:

I wanted it will be:
ex.errno=2, ex.msg=CreateFileA (File not found), lasterror=2


Here's the right way to do this:

// test.d //
import std.c.windows.windows;
import std.string : toStringz;
import std.windows.syserror : wenforce;

void main ()
{
auto handle = CreateFileA(toStringz(nonexisting),
GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
null);
wenforce(handle != INVALID_HANDLE_VALUE, CreateFileA);
}


See std.windows.syserror for more information.