William McKee 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.

Matt wrote some stuff for the guide explaining why the die handler is 
not the best approach.  Basically, it means all errors will be treated 
the same.

> Oh, so if I handle the error myself, I should unset $@?

No, I think I was wrong about that.  You shouldn't need to unset it 
yourself.

> 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.

I don't recommend that.  There's no reason to use Error instead of just 
an eval block.  It can be this simple:

eval {
   ... your code here ...
};
if ($@) {
   ... print nice error page with $@ message ...
}

This will only work if you turn off all the DIE handlers.

> 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;`.

As you discovered, this seems to be interference from the debugger.  I'm 
not sure how to turn that off, although you could probably look at 
perl5db.pl and edit it.

- Perrin

Reply via email to