Re: [Templates] how to see error messages
[prev]
[thread]
[next]
[Date index for 2005/04/12]
I asked:
> Dave> My problem is that some_method is dying but I don't get any diagnostic
> Dave> output. It seems as though TT just swallows the message. I've tried
Randal L. Schwartz wrote:
> or be sure you're looking at the errors coming out of ->process:
> eval {
> ...
> $tt->process(...)
> or die $tt->error;
> ...
> };
> if ($@) {
> if (UNIVERSAL::isa($@, "Template::Exception")) {
> ## error came from Template or below
> if ($@->type eq "undef") { # yes, the letters u n d e f!
> die $@->info; # the error from below Template (perl code plugins)
> } else {
> ## the error came from a Template step, do what you want
> die "$@"; # stringifies the Template error
> }
> } else {
> ## the error came from above Template (something else in the eval)
> die $@; # throw it again
> }
> }
Thanks for this code. I'm still having the problem so I've put together
another small test case using your code. The three files are below. The
test program processes a template which calls a Perl class that tries to
execute a non-existent method. But the error message doesn't appear.
When the program is run, it prints 'success', despite having encountered
a non-existent method call. If the eval is uncommented, it prints
Can't locate object method "no_such_number" via package "MyTest"
(perhaps you forgot to load "MyTest"?) at MyTest.pm line 9.
miracle success
Cheers, Dave
test.pl
-------
#!/usr/bin/perl
use strict;
use warnings;
use Template;
use lib '.';
my $tt = Template->new();
eval {
$tt->process('test.tt') || die $tt->error();
};
if ($@) {
if (UNIVERSAL::isa($@, "Template::Exception")) {
## error came from Template or below
if ($@->type eq "undef") { # yes, the letters u n d e f!
die $@->info; # the error from below Template (perl code
plugins)
} else {
## the error came from a Template step, do what you want
die "$@"; # stringifies the Template error
}
} else {
## the error came from above Template (something else in the eval)
die $@; # throw it again
}
}
test.tt
-------
[% USE Test = Class('MyTest') ;
Test.method() ;
'success'
%]
MyTest.pm
---------
package MyTest;
use strict;
use warnings;
sub method
{
my $self = shift;
#eval{
my $s = $self->no_such_number();
#};
print STDERR $@ if $@;
return 'miracle ';
}
1;
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates