www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - ErrnoException

reply Jirka <nope nope.com> writes:
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?
Feb 28 2016
parent reply Mike Parker <aldacron gmail.com> writes:
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
Feb 28 2016
parent reply Jirka <nope nope.com> writes:
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?
Feb 29 2016
parent reply Chris Wright <dhasenan gmail.com> writes:
On Mon, 29 Feb 2016 21:55:49 +0000, 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.
Feb 29 2016
parent reply Jirka <nope nope.com> writes:
On Monday, 29 February 2016 at 23:41:51 UTC, Chris Wright wrote:
 On Mon, 29 Feb 2016 21:55:49 +0000, 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).
Feb 29 2016
parent reply Mike Parker <aldacron gmail.com> writes:
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.
Feb 29 2016
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Mar 01 2016