"Cees Hek" <[EMAIL PROTECTED]> wrote on 07/31/2006 12:01:39 PM:
> Just a tiny correction (probably just a typo on your part since I
> believe you wrote the original error_mode patch ;-) ). It only wraps
> the execution of the actual runmode in an eval bock. It would be nice
> if it would also catch errors in all of the hooks and callbacks, but
> it is not currently implemented that way.
I think CGI::Application's error handling would benefit greatly by
eval{}ing hooks. I routinely find myself executing code that might die()
inside of a setup() routine (and/or hook) and then having to set some kind
of flag so I can defer error checking until the runmode executes. It's
workable, but kind of a pain.
sub maab_hook_init {
my $self = shift;
my @args = shift;
$self->{'__INIT_COMPLETE'} = 0;
eval {
... dangerous code such as establishing a database
connection
};
if ($@) {
$self->{'__ERROR_MESSAGE'} = $@;
return;
}
$self->{'__INIT_COMPLETE'} = 1;
}
sub maab_hook_prerun {
my $self = shift;
my $rm = shift;
if ($rm eq 'error') { return; }
# check to see if hook_init had problems;
# hook_prerun is the only place we can change the runmode
if (!$self->{'__INIT_COMPLETE'}) {
$self->prerun_mode('error');
}
}
sub error {
my $self = shift;
my $error = shift || $self->{'__ERROR_MESSAGE'};
... notify someone
my $output = ... generate error page
return $output;
}
Y-U-C-K.
Todd
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]