David Martin wrote:
> I have a template with an error in it that I just can’t seem to track
> down.
Hi David,
I see from the replies that you've already got the solution so this is
really just to fill in some of the details for anyone who's interested.
TT2 doesn't throw errors as exceptions (well, it does internally, but
the process() method hides that from you). So you have to check the
return value from process() and call error() if it's not true to find
out what went wrong.
With the benefit of 10+ years hindsight, I now know that this is a
mistake. Using return values to indicate errors is almost always a Bad
Thing[tm] because people inevitably forget (or don't know) to check them
(among other reasons). So the process() method in TT3 will instead throw
errors (by default) which will hit you square in the face. Unpleasant as
it is to be walloped in the mush by an unexpected error message, it's
generally better than being left out in the cold wondering what went wrong
(or worse still, not realising that something went wrong at all).
> I seem to recall from years ago that there is a way to tell the
> TT compiler to compile the template file and in that way discover the
> line number where it breaks?
Yes, that all happens automagically. When TT compiles the template down
to Perl code it adds #line markers that define the name and line of the
source template from whence it came. Like this:
#line 22 your/template/name
Then if an error occurs when the template code is run, Perl will report
the error happening at, for example, line 22 of your/template/name.
Cheers
A
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates