digitalmars.D.learn - std/process.d: nothrow functions which throw (in struct ProcessPipes)
- Drone1h (15/15) Jul 21 2020 Hello All,
- Adam D. Ruppe (10/11) Jul 21 2020 nothrow only applies to Exception and its children. Error is a
- Steven Schveighoffer (4/18) Jul 21 2020 We need a way to mark posts like "I got this one", so we don't spend the...
- Drone1h (6/6) Jul 23 2020 Steven Schveighoffer, Adam D. Ruppe, I wish to thank you both for
- Steven Schveighoffer (8/27) Jul 21 2020 nothrow only pertains to Exceptions, not Errors.
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.
Jul 21 2020
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.
Jul 21 2020
On 7/21/20 8:49 AM, Adam D. Ruppe wrote:On Tuesday, 21 July 2020 at 12:44:23 UTC, Drone1h wrote: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. -SteveWould 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.
Jul 21 2020
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 !
Jul 23 2020
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
Jul 21 2020