All asserts need to have messages attached! Explicit as possible!

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 7 18:10:41 PDT 2017


On 08.07.2017 02:55, FoxyBrown wrote:
> I came across some error in heap sort. Was erroring out on the wrong. A 
> few lines below the assert existed but no error message associated, why 
> is it so hard to not write a few extra EXTREMELY helpful error messages?
> 
> assert(isHeap(r), "This is an ERROR AT THIS 
> LOCATION"~__FILE__~"("~__LINE__~")");
> 
> etc?
> 
> It should be mandatory that all asserts, throws, etc provide correct 
> information about not only the point of the error but also the location 
> and what caused it. These things are not irrelevant but affect all those 
> that use it... imagine the real human man hours that could be saved if 
> such things were done.
> 
> It would be easy to find all the bad asserts?

It think the main issue is that the assertion failure had the wrong 
location information. This is not supposed to happen. Do you have a 
small example that demonstrates the issue?


I think that as long as the location is correct, the rest can be 
reconstructed without wasting a lot of time. (Of course, this is no 
excuse for Phobos not providing a more informative error message.)


More information about the Digitalmars-d mailing list