[Templates] Throwing exceptions within loops

laurence.thompson@jpmorgan.com laurence.thompson@jpmorgan.com
Sat, 11 Jan 2003 17:14:38 +0000


I'm having problems with uninitialized values if any TT2 code throws an
exception within a foreach or while loop.  There's a trivial example below.
Various attempts at debugging this have shown that the error occurs around
the "die $@ if $@" line generated at the end of the loop code.  At some
point $@ becomes undefined, but it's not obvious to me how or where.  Any
attempt at catching the error, either in the template or at the calling
level is ignored.

Any help would be greatly appreciated.  Usual apologies if this has been
seen and fixed before.

Laurence

Versions (can't be changed easily as this is intended for a production
environment) :
      Template 2.08 stable
      perl 5.005_03 built for sun4-solaris-thread
      Solaris 2.5.1

% cat throw.pl
#!/bin/env perl -w

use Template;
#$Template::Parser::DEBUG = $Template::Parser::DEBUG = 1;

$p = Template->new({
        DEBUG => 1,
        });

$p->process(\*DATA) || die $p->error;

print STDERR "No errors !\n";

__DATA__
[% THROW any 'any error' FOREACH a = [1, 2, 3]; %]
End of template

% throw.pl
Use of uninitialized value at (eval 2) line 31, <DATA> chunk 1.

## input file handle line 1 : [% THROW any 'any error' FOREACH a = [1, 2,
3]; %] ##
No errors !


This communication is for informational purposes only.  It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan Chase & Co., its
subsidiaries and affiliates.