darren chamberlain wrote:
>Myk Melez <[EMAIL PROTECTED]> said something to this effect on 08/08/2001:
>
>>I'd like to specify a template to catch exceptions thrown by the
>>Template Toolkit itself (f.e. syntax errors in my directives) in
>>addition to those exceptions I throw with a THROW directive. I am
>>currently catching these exceptions like so:
>>
>>$::template->process("MyTemplate.atml", $::vars)
>> || MyExceptionHandlingFunction($::template->error());
>>
>>Is there any way to specify that these types of errors should be handled
>>by the template specified in the ERROR configuration option (perhaps
>>with a fall-back to an exception handling mechanism if that template
>>also fails)?
>>
>
>How about:
>
> eval {
> $::template->process("MyTemplate.atml", $::vars)
> || die $::template->error
> };
>
> MyExceptionHandlingFunction($@) if ($@);
>
>(darren)
>
This would make the code even more complicated. I'm trying to simplify the code by
removing exception handling from the line where I call $::template->process. So
instead of doing this every time I want to call a template:
$::template->process("MyTemplate.atml", $::vars)
|| MyExceptionHandlingFunction($::template->error());
I do this once:
$::template = Template->new(
{
ERROR => 'MyErrorTemplate.atml'
}
);
And then process a template with:
$::template->process("MyTemplate.atml", $::vars);
This makes my code cleaner and reduces redundancy when processing a number of
templates, but it doesn't work because the toolkit only processes the error template
when I throw an exception explicitly; toolkit-thrown errors don't cause trigger the
error template.
-myk