[Catalyst] $c->forward and Exception

Tatsuhiko Miyagawa miyagawa at gmail.com
Fri Jan 27 23:36:05 CET 2006

I have a Catalyst app which code goes like:

  sub foo : Local {
      my($self, $c) = @_;

  sub bar : Private {
      my($self, $c) = @_;
      throw My::Exception() if cond();

I thought do_something() is not executed when bar throws an Excpetion.
But it wasn't true. Because forward() is executed in eval {} and
excpetion is set to $c->error, do_something() *is* executed.

Apparently, I have to write something like:

  die $c->error if $c->error;

everywhere, to make forward() DWIM.

1) The current $c->forward() behaviour doesn't look intuitive. You'd
probably need to document it at least.

2) I'm currently thinking about adding the forward wrapper to do what
I mean, like:

  sub forward_nice {
      my $c = shift;
      die $c->error if $c->error;
      return $c->state;

Do you think it's a good idea? If not, lemme know the reason, and
point me to the alternative solution.

Tatsuhiko Miyagawa

More information about the Catalyst mailing list