I think the die-message is available in $@ only in case the die happens within an eval{} block (in which case I personally wouldn't want to be mailed).
If the die happens outside of an eval, however (i.e. when the script atually dies), the message is only available in @_. (Also, I suppose your code should be mail($err), as the localized $@ would always be empty...)
In other words, I'd use something like
#!/usr/bin/perl use strict; use warnings; use Carp; $SIG{__DIE__} = sub { die @_ if $^S; # skip handler for eval{} blocks mail(@_); }; sub mail { chomp(my $msg = shift); print qq(mailing "$msg"...\n\n); } sub test { eval { croak "bar"; }; # doesn't send mail croak "foo"; # sends mail (and dies) } test(); __END__ $ ./827866.pl mailing "foo at ./827866.pl line 19 main::test() called at ./827866.pl line 22"... foo at ./827866.pl line 19 main::test() called at ./827866.pl line 22
In reply to Re^2: Improving the Error Handling of my Scripts
by almut
in thread Improving the Error Handling of my Scripts
by Dru
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |