sub cgiapp_prerun { my $this = shift; my $rm = shift; eval { ... }; if($@) { $this->stash->{exception} = "Error in prerun: $@"; $this->prerun_mode("error"); } } sub error { # error-runmode my $this = shift; my $exception = shift || $this->stash->{exception} || "default error message goes here"; ... }