Assertions getting corrupted
Johan Engelen
j at j.nl
Thu Oct 26 06:32:20 UTC 2017
On Thursday, 26 October 2017 at 06:04:56 UTC, Shachar Shemesh
wrote:
>
> There's a fundamental problem with scope(exit) and
> scope(failure). Consider the following code:
>
> {
> a = allocate_something();
> scope(exit) a.cleanup();
>
> ...
>
> assert(a.nothingHorribleWentWrong);
> }
>
> Ideally, if that assert fails, you'd want the core dump and
> backtrace from the assertion point. That's the earliest point
> in which the problem is visible.
>
> Except, all too often, what will happen is that the assert will
> throw an AssertionError. The scope(exit) will run, and then
> a.cleanup will segfault because, well, something horrible *did*
> go wrong. This makes it much more difficult to find out what
> actually went wrong.
Destructors will have the same problem, right?
It seems to me that the cause of the problem is that `assert`
throws instead of aborting execution right there.
-Johan
More information about the Digitalmars-d
mailing list