[Issue 17226] Exception during the generation of an assert message hides AssertError
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Dec 8 16:55:02 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=17226
Steven Schveighoffer <schveiguy at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |schveiguy at gmail.com
--- Comment #12 from Steven Schveighoffer <schveiguy at gmail.com> ---
What about creating a wrapper for format:
```d
string assertFormat(Args...)(string fmt, Args args)
{
try {
return format(fmt, args);
} catch(Exception ex) {
return "Error while evaluating assert message: " ~ ex.toString;
}
}
// use like
assert(i == 42, assertFormat("Something %s", functionThatThrows()));
```
This solves the problem, and also doesn't throw away any information. Plus it's
not unpleasant to use.
Yes, it's opt in. So what? It can just be a best practice recommendation.
--
More information about the Digitalmars-d-bugs
mailing list