perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lincoln Stein <lst...@cshl.org>
Subject Re: CGI::Carp
Date Thu, 15 May 2003 14:47:47 GMT
There are two uses of CGI::Carp:

	1) place time-stamped entries in the httpd error log (rather than unstamped 
entries by default)
	2) send fatal errors -- including compile time errors! -- to the browser

What I'll do is to distinguish between these two uses and only override 
$SIG{__DIE__} when the user has requested behavior (2).

Lincoln

On Sunday 11 May 2003 09:21 pm, Stas Bekman wrote:
> Lincoln Stein wrote:
> > Sorry, but even when placed in a BEGIN {} block, CORE::GLOBAL::die won't
> > catch compile-time errors the way that $SIG{__DIE__} does.
> >
> > Do you have a workaround?  Otherwise I'm going to go back to using the
> > %SIG magic in CGI::Carp.
> >
> > Here's my test script:
> >
> > #!/usr/bin/perl
> >
> > BEGIN {
> >   *CORE::GLOBAL::die = \&mydie;
> > }
> > foo bar baz;
> > print STDERR "VERSION = $]\n"; print STDERR "line 1\n";
> > die "dieing here\n";
> > print STDERR "line 2\n";
> > sub mydie {
> >   print STDERR "In die handler\n";
> >   CORE::die $@;
> > }
> >
> > Its output is
> >
> > 	Can't locate object method "foo" via package "bar" (perhaps you forgot
> > to load "bar"?) at foo.pl line 6.
> >
> > When I replace the BEGIN block with $SIG{__DIE__}=\&mydie, i get:
> >
> > In die handler
> > Died at foo.pl line 11.
>
> Indeed. *CORE::GLOBAL::die = \&mydie; overrides calls to die(), when it's
> explicitly called. It doesn't provide a replacement for situations where
> perl dies elsewhere. A call to:
>
> foo bar baz
>
> calls Perl_vcroak, which sees no PL_diehook ($SIG{__DIE__}) defined,
> neither it's executed in the eval {} block, so it writes the error message
> to the console and exits.
>
> Perhaps you want to execute this code in the eval block? Then it'll work as
> expected:
>
> #!/usr/bin/perl
>
> BEGIN {
>      *CORE::GLOBAL::die = sub {
>          print STDERR "In die handler\n";
>          CORE::die $@;
>      }
> }
>
> eval { foo bar baz; };
> die $@ if $@;
>
> print STDERR "VERSION = $]\n"; print STDERR "line 1\n";
> die "dieing here\n";
> print STDERR "line 2\n";
>
> Otherwise using $SIG{__DIE__} is the only catch-all way to do that. Though
> if you do that, you have to make sure to respect $^S flag/ using caller()
> as explained here:
> http://perl.apache.org/docs/general/perl_reference/perl_reference.html#Alte
>rnative_Exception_Handling_Techniques
>
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
========================================================================
Lincoln D. Stein                           Cold Spring Harbor Laboratory
lstein@cshl.org			                  Cold Spring Harbor, NY
========================================================================


Mime
View raw message