[Petal] Handling/rethrowing errors in Petal

Mark Holland mark at thinkfoo.com
Mon Apr 28 02:44:28 BST 2003


Hi Jean-Michel,

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

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?

Finally, thanks for putting in the perfomance enhancements. As usual my 
day job is ensuring I have zero time to work on my Petal stuff so I 
haven't had a chance to benchmark the improvement, but it seems to be 
quite noticeable.

Hope you're enjoying/enjoyed your holiday.

Cheers,
Mark



More information about the Petal mailing list