[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: $^S and eval
Tom Christiansen wrote:
> Due to an implementation glitch, the C<$SIG{__DIE__}> hook is called
> even inside an eval(). Do not use this to rewrite a pending exception
> in C<$@>, or as a bizarre substitute for overriding CORE::GLOBAL::die().
> This strange action at a distance may be fixed in a future release
> so that C<$SIG{__DIE__}> is only called if your program is about
> to exit, as was the original intent. Any other use is deprecated.
Fair enough. What, then, would be the most legitimate way of
(effectively) subclassing C<die> for a script? I ask as I use an
exception module here (in a mixture of straight Perl, Perl CGI and
mod_perl scripts) that currently contains a C<$SIG{__DIE__}> handler
that encapsulates the error text and re-dies. The code does a fair bit
of extra processing (munging text, optional stack traces etc.) but it
boils down to:
INIT {
my $oldHandler=$SIG{__DIE__} || 'DEFAULT';
$SIG{__DIE__}=sub {
my $err=ref $_[0] ? shift : bless {TEXT=>join '', @_};
if (!defined $^S || $^S) {
local $SIG{__DIE__}=$oldHandler;
die $err;
} else {
$err->croak;
}
};
}
thus allowing me to do C<eval {die 'aargh'}; $@ and $@->croak> without
having to worry if $@ is an exception object or not.
Pete
--
use Disclaimer::Standard; # Motorola GSM Software Factory
my $phone='+44 1793 564450'; # "'Not twisted,' Salzy once said of
my $fax='+44 1793 566918'; # her own passion, 'it is helical.
my $mobile='+44 7973 725120'; # That sounds better.'"
- References to:
-
Tom Christiansen <tchrist@chthon.perl.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]