Better error messages - from reddit

Walter Bright newshound2 at digitalmars.com
Tue Mar 5 02:57:04 UTC 2019


On 3/4/2019 5:23 PM, Nicholas Wilson wrote:
> On Tuesday, 5 March 2019 at 01:07:08 UTC, Walter Bright wrote:
>> Use of `static if` and `pragma(msg)` can be used to generate custom error 
>> messages:
>>
>>     static if (!isInputRange(r)) pragma(msg, r, " must be an Input Range");
> 
> That doesn't work if you need to overload against it because then you will cause 
> a matches multiple template error.

Frankly I think the use of overloads in D has gone too far. Anyhow, the above 
shows the principle. With some careful coding, it can work for the various 
scenarios.


More information about the Digitalmars-d mailing list