[Catalyst] Custom error handling

kakimoto at tpg.com.au kakimoto at tpg.com.au
Sun Jul 5 04:32:58 GMT 2009

hello, Tomas,

 thank you :) My replies are as per below.

> You mean you're calling $c->error yourself in your own controller
> code?

Yes I am.
> You haven't shown us the code you're putting stuff into $c->error  
> with, therefore it's pretty hard to tell how you're doing it wrong.

---- Extract from Controller (Start) ----
sub _save_address
    if ($@)
        $c->log->debug('Exception while saving address - '. $@);

            q{ An error has occured with the address entered. Please
ensure } .
            q{that you have entered a valid address. If this persists, } .
            q{please contact our helpdesk at helpdesk at loadproperty.com.au.}
    return $address->id;

---- Extract from Controller (End) ----

> Try just putting:
> die("An error")
> into your controller code, and you should see that captured in $c- 
>  >error when it gets to your end action
yes, when i did that in my controller code, this is what I saw on the
terminal's logs:

[error] Caught exception in myApp::Controller::Listings->_save_address
"An error  at
line 590."

 When I remove "-Debug" from myApp.pm, I get just the generic screen
saying "Please come back later" whilst when I have "-Debug" there in
myApp.pm, I get a screen with the following message in the web browser.

"Caught exception in myApp::Controller::Listings->_save_address "An
error at
line 590."

 My Root->end now looks like this:

sub end : ActionClass('RenderView') {
    my ($self, $c) = @_;

    $c->log->debug(" Calling END in Root "
    #. Data::Dumper->Dump([$c->error])

     if ( scalar @{ $c->error } ) {
        $c->log->debug(' Found an error in Root' );
        $c->stash->{errors}   = $c->error;
        $c->stash->{template} = 'menu.tt';
        $c->log->debug(" nothing done ");
   return 1;

 In the terminal logs, I do get the message, "Found an error in Root"
BUT it doesn't load the template i specified (menu.tt2).

Any idea of how to get a custom screen up?

More information about the Catalyst mailing list