What should happen when the assert message expression throws?

Ali Çehreli acehreli at yahoo.com
Fri Nov 25 12:29:26 UTC 2022


On 11/25/22 00:12, Dukc wrote:

 >> Discussion: As I commented on the bug report as well, D is already in
 >> the best-effort business when it comes to Errors:
 >
 > What does "best-effort" mean?

(I am not sure whether I should have used the word "hopeful" here. I 
will continue with best-effort.)

According to common assert wisdom, the program must not continue once an 
assertion has failed because the program is in invalid state.

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.

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.

That logic can be carried all the way down to hardware and in the end 
most computing is best-effort anyway.

Given all that, D's assert behavior can do anything it wants so I still 
agree with the code above but I think it can be improved by caching 
Throwable in message generation because the programmer would still be 
interested in the original failed assert:

   catch (Throwable exc)

Ali



More information about the Digitalmars-d mailing list