Skip to content

Commit

Permalink
auto-handle errors for the subclasser
Browse files Browse the repository at this point in the history
  • Loading branch information
jrockway committed Aug 17, 2007
1 parent 4af23e5 commit 8961d89
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/Catalyst/View/Templated.pm
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,17 @@ sub _do_render {
$stash->{base} ||= $self->context->request->base;
$stash->{name} ||= $self->context->config->{name};

return $self->_render($template, $stash, $args);
my $output = eval {
$self->_render($template, $stash, $args);
};

if ($@) {
my $error = "Couldn't render template '$template': $@";
$self->context->error($error);
die $error;
}

return $output;
}

=head1 IMPLEMENTING A SUBCLASS
Expand Down Expand Up @@ -232,7 +242,14 @@ Don't use NEXT anymore.
=item
Returning false from C<_render> is not an error. If something bad
happens, throw an exception.
happens, throw an exception. The error will automatically be handled
appropriately; all you need to do is die with an informative message.
The message shown to the user it:
Couldn't render template '$template': $@
C<$@> is whatever you invoked C<die> against.
=back
Expand Down

0 comments on commit 8961d89

Please sign in to comment.