in reply to try catch getting ignored by SIG DIE subroutine

Hello dkhosla1,

See also the entry for %SIG in perlvar#General-Variables.

I really need the SIG_DIE functionality for the rest of the code, just not have it get int he way in the try/catch section :-).

You can disable the signal handler for just the section(s) of code containing try/catch:

use strict; use warnings; use Try::Tiny; $SIG{__DIE__} = sub { chomp(my $item = shift); print STDERR "DIE ERROR: $item\n"; exit 2; }; # ... code here ... my $last_sig_die = $SIG{__DIE__}; # Save current setting $SIG{__DIE__} = 'DEFAULT'; try { die 'Dying'; } catch { print STDERR $_; # Note: $_, not $@ }; $SIG{__DIE__} = $last_sig_die; # Restore setting die 'Really dying';

Output:

17:42 >perl 1871_SoPW.pl Dying at 1871_SoPW.pl line 19. DIE ERROR: Really dying at 1871_SoPW.pl line 28. 17:42 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: try catch getting ignored by SIG DIE subroutine
by dkhosla1 (Sexton) on Feb 25, 2018 at 20:11 UTC
    Thanks Athanasius. This should help. Will try with the 'local' enhancement suggested by haukex.