What should happen when the assert message expression throws?
Ali Çehreli
acehreli at yahoo.com
Fri Nov 25 15:48:49 UTC 2022
On 11/25/22 07:33, kdevel wrote:
> On Friday, 25 November 2022 at 14:38:57 UTC, Ali Çehreli wrote:
>> On 11/25/22 05:32, kdevel wrote:
>
>> If that assertion fails, the program is in an invalid state.
>
> [reordering ...]
>
>> > int main ()
>> > {
>> > int a = 1;
>> > try
>> > assert (a == 0);
>> > catch (Throwable t)
>> > {}
>> > return 0;
>> > }
>> >
>> > Which line makes the program enter the "invalid state"?
I am not an expert here; just philosophizing.
[reordering...] :)
>> Although that looks like a bug in the programmer's mind, I can still
>> imagine the programmer expected some code perhaps running in a thread
>> started e.g. in a 'static this' block was expected to alter the stack.
>
> The fabricated nine lines of code above is all I have. No static this
> block. It is meant as it is.
>
Your example proves that we all assume that the assertion condition is
correct. I don't think the example above has a correct condition; so
let's focus on correct ones.
> Is it in the "invalid state" right after the condition has been
> evaluated or not before the AssertError has been thrown? What if the
> program is compiled with -release? Is it still in "invalid state"?
I think assert is just a tool that exposes an invalid state. The invalid
state may have been reached long ago. That's why I say the whole assert
mechanism starting with executing the condition all the way down to
printing backtrace or even not doing anything at all is best-effort.
I am fine with that because such is life. But in philosophy, it gives us
liberty to do anything we want.
Ali
More information about the Digitalmars-d
mailing list