package Whatever::Controller use Mojo::Base qw(Mojolicious::Controller); use Whatever::Thingy; use Whatever::Exceptions; # <- based on Class::Exception sub do_something { my($this)=@_; my $input = $this->param("input"); # the following constructor potentially throws an exception my $thingy = Whatever::Thingy->new( input => $input ); $this->stash( thingy=> $thingy ); $this->render( format => "html", template => "thingy_template", ); } } sub render_exception { my($this, $ex)=@_; # now do something based on the class of $ex if($ex->isa("Whathever::Exception::SourMilk") { $this->render( format => "html", template => "exception", status => 501, ex => $ex, ); } else {.....} # and so on } 1;