Andy Wardley writes:
> Randal L. Schwartz wrote: > >>Well, I like to wrap my PROCESS $template in a TRY block, so that >>won't work very well. > > It will if you add the ERROR option. This can be used to define a > template or subroutine to be invoked when the main PROCESS/WRAPPER > fails. You can also define it as a hash mapping error types to > templates/handlers, effectively the same thing as having multiple > CATCH blocks.
Note to self: Remember to re-read the docs from time to time. ERROR apparently has been there since the very start of TT2, and I haven't been aware of it.
I know that I do not wrap my PROCESS $template in a TRY block, but after reading Randal's comment I was pretty sure that I *should*, at least for dynamic content. For my ttree pages I'd rather have ttree complain loudly than to more or less silently fall back to some error template.
OTOH the code creating my dynamic web content today checks for $tt->error() and drops a note in the logfile in case of errors (and it fires off a simple text/plain error message to the gentle reader). If I switch to using an ERROR template I can show a "corporate design" error page easily, but I'd have to find some other method for reporting the error to myself.
But alas, there's the mail plugin in the badger page 327 ff. which could do the trick neatly.
Note to self (2): Remember to re-read the badger from time to time.
Two questions come into my mind (without helping much regarding the ERROR option vs. error() method decision):
- You write that one can define a subroutine to be invoked in case of errors. As of 2.14 (and badger), only templates are documented. Is this a TT3 or an undocumented TT2 feature?
- I found it a bit painful to find out the error types experimentally (until I eventually found the list in Template/Constants.pm). Is there a list of error strings created by TT somewhere in the docs?
-- Cheers, haj
_______________________________________________ templates mailing list [email protected] http://lists.template-toolkit.org/mailman/listinfo/templates
