Re: [Templates] how to see error messages

[prev] [thread] [next] [Date index for 2005/04/12]

From: Dave Howorth
Subject: Re: [Templates] how to see error messages
Date: 15:09 on 12 Apr 2005
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

[Templates] how to see error messages
Dave Howorth 12:36 on 11 Apr 2005

Re: [Templates] how to see error messages
merlyn (Randal L. Schwartz) 14:45 on 11 Apr 2005

Re: [Templates] how to see error messages
merlyn (Randal L. Schwartz) 14:51 on 11 Apr 2005

Re: [Templates] how to see error messages
Dave Howorth 15:09 on 12 Apr 2005

Re: [Templates] how to see error messages
Andy Wardley 07:24 on 13 Apr 2005

Re: [Templates] how to see error messages
Dave Howorth 09:36 on 13 Apr 2005

Re: [Templates] how to see error messages
Dave Howorth 10:23 on 14 Apr 2005

Generated at 09:31 on 27 Apr 2005 by mariachi v0.52