Return-Path: Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 70922 invoked by uid 500); 12 May 2003 01:21:16 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 70911 invoked from network); 12 May 2003 01:21:16 -0000 Message-ID: <3EBEF70C.1030502@stason.org> Date: Mon, 12 May 2003 11:21:16 +1000 From: Stas Bekman Organization: Hope, Humanized User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: en-us, en MIME-Version: 1.0 To: lstein@cshl.org Cc: Daisuke Maki , jhi@iki.fi, modperl@perl.apache.org Subject: Re: CGI::Carp References: <3E9633FA.5030008@stason.org> <3EBEDDEA.3050403@wafu.ne.jp> <3EBEE0B1.5040600@stason.org> <200305112032.09359.lstein@cshl.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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#Alternative_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