assert with format considered harmful

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 25 22:34:07 PST 2017


If the generation of the error message throws, then the program receives 
a FormatException, not the most import AssertError:

import std.string;

void foo(int i) {
     // In this case a %s is forgotten but it could be any other trivial 
error.
     assert(i == 42, format("Bad parameter:", i));
}

void main() {
     foo(43);
}

Opened:

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

So, obviously, assert message generation is not lazy. This is a WAT! for 
me but perhaps there is a good reason for it.

Google found a related article by Peter Alexander:

   http://poita.org/2012/09/02/a-better-assert-for-d.html

Ali


More information about the Digitalmars-d mailing list