[Templates] Template::ERROR

Perrin Harkins perrin at elem.com
Wed Jan 9 21:35:53 GMT 2008


On Jan 9, 2008 3:05 PM, Kate Yoak <kate at yoak.com> wrote:
> Sure, I could parse the $Template::ERROR text - but it seems like there
> ought to be a better way to do it.

Template::Exception has a type, which may be useful to you.  I'd
suggest grep'ing the code to see what some possible types are when it
throws Template::Exception errors.

> I read a lot of documentation concerning using try/catch inside a template
> but none for how to do it in code. I tried the common try/catch syntax
> associated with Error.pm - but that doesn't work.

That only works with things that throw exceptions, which process()
does not.  It makes you check for a true return value and then look at
$tt->error() or $Template::ERROR.  I recommend avoiding Error.pm's
try/catch anyway, because of the error-prone sub ref prototype trick
it uses.

The error() method should give you a Template::Exception object, as
described here:
http://tt2.org/docs/modules/Template.html#method_error

- Perrin



More information about the templates mailing list