[Petal] Re: Handling/rethrowing errors in Petal

Jean-Michel Hiver jhiver at mkdoc.com
Mon May 19 14:56:49 BST 2003


> Hi Jean-Michel,

Hi Mark,


> I have finally had some time to work on my petal-involving projects.

Good!


> Whilst converting one site over to petal I have come across a problem 
> with my mason/petal set up that required me to hack out my own version. 
> The problem is, as I chain mason components and petal objects together 
> my mason-generated errors are not being propagated up the chain. Instead 
> they are getting stringyfied by petal, meaning that what mason would 
> usually treat only as a warning, is being treated as a fatal error.
> 
> Quite simply, I need to be able to subclass petal and substitute in my 
> own error handling at the end of the proccess routine.
> 
> E.g. where petal currently does this:
> 
> line 235:
>    eval { $res = $coderef->($hash) };
>    if (defined $@ and $@) { confess $@ . "\n===\n\n" . 
> $self->_code_with_line_numbers }
>    return $res;
> 
> it could call its own 'handle_error' method:
> 
>    eval { $res = $coderef->($hash) };
>    $self->handle_error($@);
> 
> and in the subclass i would then be able say:
> 
> sub handle_error {
>       my $self = shift;
>       my $err = shift;
>      
>       if (defined $err and $err) {
>            if  (isa_mason_exception($err)) {
>              die $err;
>            } else {
>              confess $@ . "\n===\n\n" . $self->_code_with_line_numbers;
>             }
>       }
> }
>            
> (isa_mason_exception is a imported routine which simply checks that $err 
> belongs to the html::mason::exception class)
> 
> Just a  suggestion, perhaps there's a better way?

This looks good to me. I'll do that bit of refactoring and make a
release soon so that you can handle Mason errors correctly.


> Hope you're enjoying/enjoyed your holiday.

I just came back yesterday. It was brilliant! French polynesia is well
worth visiting, especially if like me you like scuba diving :).

Cheers,
-- 
Building a better web - http://www.mkdoc.com/
---------------------------------------------
Jean-Michel Hiver
hiver at mkdoc.com  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/


More information about the Petal mailing list