Thread overview
Building good error message in templates?
Mar 12, 2007
renoX
Mar 13, 2007
Daniel Keep
Sep 19, 2007
johannes
March 12, 2007
One problem with the templates is that currently when there is an error, the line number showed in the message is the line in the template and there is no way to print the line number of the caller except by having the caller do myTemplate!(__LINE__, ...) which is quite ugly.

For a mixin, an advice was to return a 'static assert' which would be evaluated in the caller, this works ok when the caller is a function, but it doesn't work very well when the caller is used for example as a function parameter.

Are there other way I'm missing?
renoX
March 13, 2007
renoX wrote:
> One problem with the templates is that currently when there is an error, the line number showed in the message is the line in the template and there is no way to print the line number of the caller except by having the caller do myTemplate!(__LINE__, ...) which is quite ugly.
> 
> For a mixin, an advice was to return a 'static assert' which would be evaluated in the caller, this works ok when the caller is a function, but it doesn't work very well when the caller is used for example as a function parameter.
> 
> Are there other way I'm missing?
> renoX

Not that I'm aware of.  A while back, I suggested the addition of a context "object" that templates would have access to that would allow them to say "`Error on line ` ~ context.line" and have it come out right.

I don't think I ever received comment from our BDFL, tho :P

At the moment, tho, I suppose the best you can do is print out an error message, static assert(false), and then let the user work out where to look from the instantiation error.

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/
September 19, 2007
Hello,

there is a possibility called concepts. One way to define themn is to use boost concept check. The other is to use the compiler conceptGCC.

Actually this is for c++, I don't know if there is something like that for D.

Johannes