November 07, 2015 Re: assert(0) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fyodor Ustinov | Colleagues, IMHO:
If "assert" catch "fundamental programmers errors" - it should hang programm immediately with and without "-release".
If "assert" catch not "too fundamental" errors - assert(0) should emit "Error" in both cases.
Third option - assert(0) - it's a "special case" and halt program in both cases.
But there should't be so that in one case the "fundamental error" and the other "not fundamental".
It's my opinion.
WBR,
Fyodor.
| |||
November 07, 2015 Re: assert(0) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fyodor Ustinov | On Saturday, 7 November 2015 at 21:00:58 UTC, Fyodor Ustinov wrote:
> We do not have way to in "scope(failure)" or "scope(exit)" detect - it's "assert" or "throw".
Indeed. But the point is that _all_ Errors (of which AssertError is one example) are throwable from `nothrow` functions, and as such might not unwind the stack as you would expect.
— David
| |||
November 08, 2015 Re: assert(0) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On Saturday, 7 November 2015 at 22:26:53 UTC, David Nadlinger wrote:
> On Saturday, 7 November 2015 at 21:00:58 UTC, Fyodor Ustinov wrote:
>> We do not have way to in "scope(failure)" or "scope(exit)" detect - it's "assert" or "throw".
>
> Indeed. But the point is that _all_ Errors (of which AssertError is one example) are throwable from `nothrow` functions, and as such might not unwind the stack as you would expect.
>
> — David
Dumb question, does nothrow affect codegen?
| |||
November 08, 2015 Re: assert(0) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to rsw0x | On Sunday, 8 November 2015 at 02:51:33 UTC, rsw0x wrote:
> On Saturday, 7 November 2015 at 22:26:53 UTC, David Nadlinger wrote:
>> On Saturday, 7 November 2015 at 21:00:58 UTC, Fyodor Ustinov wrote:
>>> We do not have way to in "scope(failure)" or "scope(exit)" detect - it's "assert" or "throw".
>>
>> Indeed. But the point is that _all_ Errors (of which AssertError is one example) are throwable from `nothrow` functions, and as such might not unwind the stack as you would expect.
>>
>> — David
>
> Dumb question, does nothrow affect codegen?
I don't know if it does right now, but in the future with things like RC I'd imagine it definitely would (ARC is cheaper if you can guarantee no exceptions). I feel like there is some cases right now where it does, but I don't know about that.
| |||
November 08, 2015 Re: assert(0) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to rsw0x | On Sunday, 8 November 2015 at 02:51:33 UTC, rsw0x wrote:
> Dumb question, does nothrow affect codegen?
I'd be very surprised if it didn't. But even if it doesn't currently affect codegen, it likely will at some point in the future.
- Jonathan M Davis
| |||
November 08, 2015 Re: assert(0) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fyodor Ustinov | On Saturday, 7 November 2015 at 21:24:02 UTC, Fyodor Ustinov wrote:
> Colleagues, IMHO:
>
> If "assert" catch "fundamental programmers errors" - it should hang programm immediately with and without "-release".
>
> If "assert" catch not "too fundamental" errors - assert(0) should emit "Error" in both cases.
>
> Third option - assert(0) - it's a "special case" and halt program in both cases.
>
> But there should't be so that in one case the "fundamental error" and the other "not fundamental".
>
> It's my opinion.
>
> WBR,
> Fyodor.
I strongly disagree. Without `-release`, the job of "fundamental programmers errors" is not to stop the program and prevent farther corruption(which is pointless - how do you know executing the `scope(exit)` and `scope(failure)` blocks will increase the corruption? Maybe they'll reduce it?), because when you are developing you shouldn't work with the only copies of important data files. Without `-release`, the role of `assert`s(and `Error`s in general) is the help the programmer fix these bugs.
When I have a "fundamental programmer error" in my code, I prefer to get a stack trace from the exception mechanism than to find a core dump(that was hopefully generated) and rely on GDB's excellent support for D to analyze it.
Besides, there are some very specific cases where it's acceptable to catch `Error`s - one of them is when you have a logging mechanism that can log these errors in a way/place that's easier for you to read - and then of course re-throws them. Halting the program on errors prevents this logging mechanism from doing it's thing.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply