Jump to page: 1 2
Thread overview
assert(0)
Nov 07, 2015
Fyodor Ustinov
Nov 07, 2015
anonymous
Nov 07, 2015
Fyodor Ustinov
Nov 07, 2015
David Nadlinger
Nov 07, 2015
Fyodor Ustinov
Nov 07, 2015
Kapps
Nov 07, 2015
Fyodor Ustinov
Nov 07, 2015
anonymous
Nov 07, 2015
Fyodor Ustinov
Nov 07, 2015
anonymous
Nov 07, 2015
David Nadlinger
Nov 08, 2015
rsw0x
Nov 08, 2015
Kapps
Nov 08, 2015
Jonathan M Davis
Nov 07, 2015
Fyodor Ustinov
Nov 08, 2015
Idan Arye
November 07, 2015
Hi!

I carefully read the
http://www.digitalmars.com/d/archives/digitalmars/D/assert_0_behavior_269336.html and still have question.

Well. assert(0) located in very-very dangerous place. If we suddenly got to this place - Program should die immediately, otherwise there will be something terrible.

But without "-release" this place less dangerous? Why without "-release" this assert behaves like any other (throw exception and we can cath it, for example)?

I think assert(0) should have the same behavior with "-release" and without. May be "HLT instruction", may be "throw exception", but _the same_.

WBR,
    Fyodor.
November 07, 2015
On 07.11.2015 19:42, Fyodor Ustinov wrote:
> Well. assert(0) located in very-very dangerous place. If we suddenly got
> to this place - Program should die immediately, otherwise there will be
> something terrible.
>
> But without "-release" this place less dangerous? Why without "-release"
> this assert behaves like any other (throw exception and we can cath it,
> for example)?

Asserts throw Errors, not Exceptions. You should generally not catch Errors. That's just as dangerous without -release as with it.
November 07, 2015
On Saturday, 7 November 2015 at 18:48:40 UTC, anonymous wrote:

> Asserts throw Errors, not Exceptions. You should generally not catch Errors. That's just as dangerous without -release as with it.

1. I should generally _not_, but I _can_.
2. Without "-release" assert(0) launches scope(exit), scope(failure) and "finally" blocks. I.e. we get a completely different behavior in "-release" and not "-release" mode.

WBR,
    Fyodor.
November 07, 2015
On Saturday, 7 November 2015 at 20:38:20 UTC, Fyodor Ustinov wrote:
> 2. Without "-release" assert(0) launches scope(exit), scope(failure) and "finally" blocks. I.e. we get a completely different behavior in "-release" and not "-release" mode.

This is not guaranteed to happen for Errors either, which is part of the reason why you should pretty much never catch them.

 — David
November 07, 2015
On Saturday, 7 November 2015 at 20:40:49 UTC, David Nadlinger wrote:
> On Saturday, 7 November 2015 at 20:38:20 UTC, Fyodor Ustinov wrote:
>> 2. Without "-release" assert(0) launches scope(exit), scope(failure) and "finally" blocks. I.e. we get a completely different behavior in "-release" and not "-release" mode.
>
> This is not guaranteed to happen for Errors either, which is part of the reason why you should pretty much never catch them.

"assert" not guaranteed caught by "scope(exit)/scope(failure)/finally" ???? Where I can read about this in documentation?

WBR,
    Fyodor.
November 07, 2015
On 07.11.2015 21:38, Fyodor Ustinov wrote:
> 1. I should generally _not_, but I _can_.

D lets you to shoot your own foot, yes. You're encouraged not to do it, though.

> 2. Without "-release" assert(0) launches scope(exit), scope(failure) and
> "finally" blocks. I.e. we get a completely different behavior in
> "-release" and not "-release" mode.

Yeah, -release drastically changes how asserts behave. That's its purpose. A program should not fail asserts. If it does, that's a bug. In particular, assert(0) should never be reached. If it is reached, that's a bug.
November 07, 2015
On Saturday, 7 November 2015 at 20:48:24 UTC, Fyodor Ustinov wrote:
>
> "assert" not guaranteed caught by "scope(exit)/scope(failure)/finally" ???? Where I can read about this in documentation?
>
> WBR,
>     Fyodor.

Right. Errors indicate that something went fundamentally wrong in your program and no recovery is possible (indicates a programming error rather than an environmental error generally). So at this point the only thing to do is to close the program and stop execution. Theoretically anything might be wrong at this point, so even executing things like your finally or scope blocks could lead to corruption.

November 07, 2015
On Saturday, 7 November 2015 at 20:49:49 UTC, anonymous wrote:
> On 07.11.2015 21:38, Fyodor Ustinov wrote:
>> 1. I should generally _not_, but I _can_.
>
> D lets you to shoot your own foot, yes. You're encouraged not to do it, though.
It's my opinion - shoot to my foot or not and select preffered weapon for it. :)

>> 2. Without "-release" assert(0) launches scope(exit), scope(failure) and
>> "finally" blocks. I.e. we get a completely different behavior in
>> "-release" and not "-release" mode.
>
> Yeah, -release drastically changes how asserts behave. That's its purpose. A program should not fail asserts. If it does, that's a bug. In particular, assert(0) should never be reached. If it is reached, that's a bug.

We do not have way to in "scope(failure)" or "scope(exit)" detect - it's "assert" or "throw".

P.S.
I do not argue, "assert" - it's catch for fundamental programmers bug.

November 07, 2015
On Saturday, 7 November 2015 at 20:50:02 UTC, Kapps wrote:

> Right. Errors indicate that something went fundamentally wrong in your program and no recovery is possible (indicates a programming error rather than an environmental error generally). So at this point the only thing to do is to close the program and stop execution. Theoretically anything might be wrong at this point, so even executing things like your finally or scope blocks could lead to corruption.

Wait-wait. Without "-release" we are not afraid of anything?

WBR,
    Fyodor.

November 07, 2015
On 07.11.2015 22:00, Fyodor Ustinov wrote:
> We do not have way to in "scope(failure)" or "scope(exit)" detect - it's
> "assert" or "throw".

Ah, I get what you mean now. I think you have a point. Executing scope(failure/exit) code when an Error has been thrown may be bad. I'm not aware of the details, though.
« First   ‹ Prev
1 2