sub cgiapp_prerun { my($this, $rm)=@_; eval { ... }; if($@) { $this->stash->{exception} = $@; $this->prerun_mode("prerun_error") } } sub prerun_error { my($this)=@_; $this->error($this->stash->{exception}); } sub error { # error-runmode my($this, $exception)=@_; ... }