On 16 Sep 2002 at 18:10, Perrin Harkins wrote:
> The way that most people would recommend in A::R or anything else is to
> trap errors with eval blocks and then handle them appropriately.

I thought I was doing that at a global level by throwing an error with 
die() that was caught by CGI::Carp. I'm realizing that it isn't so simple.


> > Unfortunately, CGI::Carp is still not displaying my custom error message
> > which I set in a BEGIN block using the set_message() function.
> 
> I don't know a lot about CGI::Carp specifically, but I'm guessing it 
> tries to avoid catching any dies inside of evals, so you will probably have
> to modify it or roll your own if you want that behavior.

Ahhh, that makes sense. Of course, my application still stops executing, 
but I guess that is because the error percolated up to mod_perl then back 
down to CGI::Carp which had set the %SIG hash.
 

> > I guess this system wouldn't work if I try to
> > redefine the set_message function in other Registry scripts since 
> > CGI::Carp is not being instantiated individually in each script (or is
> > it??).
> 
> If it uses globals (as opposed to an OO interface) then it's the same
> globals for every Registry script.  That would be a problem if you only set
> it in the BEGIN block, but you could easilly set it on every execution of
> the script.

Ohh, well isn't that a good idea ;-p. I feel like a beginner all over 
again in this environment.


> If you leave $@ set, it will cause A::R to return a SERVER_ERROR status and
> apache will send a generic error page after your message.

Oh, so if I handle the error myself, I should unset $@? I didn't see this 
in the example mydie function in the Guide. However, exit 1 is called at 
the end of the subroutine which may be sufficient for bypassing the A::R 
check.

 
> You can override die, or install a signal handler for the DIE hook, or wrap
> your code in an eval block.

One of the the members of the CGI::Application mailing list suggested 
using Graham Barr's Error module and a wrap around the instantiation 
script. It's an interesting approach which I'm going to take a look at 
today.


> > Indeed, it appears that the suggestion in the Code Snippets section of
> > the mod_perl guide
> > <http://perl.apache.org/docs/1.0/guide/snippets.html#Redirecting_Errors_t
> > o_ the_Client_Instead_of_error_log> will not work as given for
> > Apache::Registry scripts.
> 
> It should work.  The signal handler is called even inside an eval.

Hmm, I'll try again. 

I still am having no luck. I've walked through the execution with the 
debugger and am finding that Carp::longmess_heavy is catching my die() 
calls despite the fact that I have set `local $SIG{__DIE__} = \&mydie;`. I 
was using the diagnostics and warnings pragmas but turned them off 
(diagnostics was catching the die before Carp). However, I'm not using 
Carp... except in my startup.pl that I copied from somewhere on the net:
        `$SIG{__WARN__} = \&Carp::cluck;`

I removed that code but am still getting Carp being called before my 
custom handler. It must be some library I'm using but why wouldn't my 
localized %SIG override this value?


Very confused,
William

-- 
 Lead Developer
 Knowmad Services Inc. || Internet Applications & Database Integration
 http://www.knowmad.com
 

Reply via email to