What should happen when the assert message expression throws?
kdevel
kdevel at vogtner.de
Fri Nov 25 13:32:53 UTC 2022
On Friday, 25 November 2022 at 12:29:26 UTC, Ali Çehreli wrote:
> According to common assert wisdom, the program must not
> continue once an assertion has failed because the program is in
> invalid state.
Whatever "invalid state" means. I could not find a definition in
the manual. Usually a system is said to be in some state s of a
set of possible states S. Now one can devise a proper subset I ⊊
S and say "the system is in an invalid state" iff s ∈ I. That is
a precise definition but is still meaningless.
> However, the main thread of a D program does execute code to
> display the backtrace to help the programmer discover why the
> assertion failed. By the wisdom above, this is best-effort
> because if the program is in an invalid state, the code that
> attempts to display the backtrace can e.g. delete files.
Pardon! What?
> I had discovered that fact when I first started catching Errors
> in non-main threads to do exactly what the main thread does. I
> used to feel guilty about that but now I know it's all
> best-effort anyway: it may or may not work.
>
> Add to the above another observation which I had after Patrick
> Schluter's message: Even the execution of the assert check is
> best-effort because if the check will fail, the program has
> been in invalid state for an unknow amount of time anyway.
int main ()
{
int a = 1;
try
assert (a == 0);
catch (Throwable t)
{}
return 0;
}
Which line makes the program enter the "invalid state"?
Additional question: What constitutes that "invalid state"?
More information about the Digitalmars-d
mailing list