Building good error message in templates?

Daniel Keep daniel.keep.lists at gmail.com
Mon Mar 12 18:37:01 PDT 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/


More information about the Digitalmars-d-learn mailing list