Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 21, 2020 std/process.d: nothrow functions which throw (in struct ProcessPipes) | ||||
---|---|---|---|---|
| ||||
Hello All, In phobos/std/process.d, in the ProcessPipes struct, we can see a few functions which are marked with "nothrow", but which (under some conditions) throw: @property File stdout() @safe nothrow { if ((_redirectFlags & Redirect.stdout) == 0) throw new Error("Child process' standard output stream hasn't " ~"been redirected."); return _stdout; } Would it be possible to explain this, please ? Or point me to some relevant documentation, please ? Thank you. |
July 21, 2020 Re: std/process.d: nothrow functions which throw (in struct ProcessPipes) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Drone1h | On Tuesday, 21 July 2020 at 12:44:23 UTC, Drone1h wrote:
> Would it be possible to explain this, please ?
nothrow only applies to Exception and its children. Error is a different branch.
Error means you have a programming error and cannot be caught and recovered (though the compiler allows it anyway, it reserves the right to just abort the program instead of actually going through the try/catch system), so it doesn't count as a normal exception, even though it is still thrown.
You are supposed to prevent Errors by fixing the bugs in your code, so in a final build they never happen.
|
July 21, 2020 Re: std/process.d: nothrow functions which throw (in struct ProcessPipes) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Drone1h | On 7/21/20 8:44 AM, Drone1h wrote:
> Hello All,
>
> In phobos/std/process.d, in the ProcessPipes struct, we can see a few functions which are marked with "nothrow", but which (under some conditions) throw:
>
> @property File stdout() @safe nothrow
> {
> if ((_redirectFlags & Redirect.stdout) == 0)
> throw new Error("Child process' standard output stream hasn't "
> ~"been redirected.");
> return _stdout;
> }
>
> Would it be possible to explain this, please ? Or point me to some relevant documentation, please ?
>
> Thank you.
nothrow only pertains to Exceptions, not Errors.
Throwing an Error isn't guaranteed to unwind the stack properly (which is why it can be done within nothrow), and the program should exit if it ever happens. An Error is a programming mistake (it should never happen if you wrote your code correctly), whereas an Exception can happen due to environmental issues or user input.
-Steve
|
July 21, 2020 Re: std/process.d: nothrow functions which throw (in struct ProcessPipes) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On 7/21/20 8:49 AM, Adam D. Ruppe wrote:
> On Tuesday, 21 July 2020 at 12:44:23 UTC, Drone1h wrote:
>> Would it be possible to explain this, please ?
>
> nothrow only applies to Exception and its children. Error is a different branch.
>
> Error means you have a programming error and cannot be caught and recovered (though the compiler allows it anyway, it reserves the right to just abort the program instead of actually going through the try/catch system), so it doesn't count as a normal exception, even though it is still thrown.
>
> You are supposed to prevent Errors by fixing the bugs in your code, so in a final build they never happen.
We need a way to mark posts like "I got this one", so we don't spend the same time saying the same thing lol.
-Steve
|
July 23, 2020 Re: std/process.d: nothrow functions which throw (in struct ProcessPipes) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer, Adam D. Ruppe, I wish to thank you both for your explanations ! I have understood and I have created a small test program. Indeed, at least on Windows, the destructor of an automatic struct does not seem to run. Have a wonderful day... and I hope to be bugging the community again soon ! |
Copyright © 1999-2021 by the D Language Foundation