[Issue 17226] Exception during the generation of an assert message hides AssertError

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 23 11:21:03 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=17226

Bolpat <qs.il.paperinik at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik at gmail.com

--- Comment #11 from Bolpat <qs.il.paperinik at gmail.com> ---
As Timon pointed out, requiring the evaluation of the assert msg to be nothrow
is a limitation, I don’t think it is a major limitation. `assumeWontThrow` [1]
is well-suited for this purpose.

I don’t think that
```d
import std.exception : assumeWontThrow;
assert(condition, assumeWontThrow(potentially throwing expr));
```
is too much to ask for. It documents clearly that the message-generating
expression could throw. That way, an Exception thrown by the message-generating
expression does not hide a bug.

[1] https://dlang.org/phobos/std_exception.html#assumeWontThrow

--


More information about the Digitalmars-d-bugs mailing list