A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Perl/perl5/issues/22984 below:

$SIG{__DIE__} handler doesn't work when called explicitly · Issue #22984 · Perl/perl5 · GitHub

Description

If you register a subroutine as a $SIG{__DIE__} handler, then call it normally, and that sub then (directly or indirectly) throws an exception, the $SIG{__DIE__} behavior doesn't kick in; i.e. the sub is not re-invoked to handle the exception.

Steps to Reproduce

$ perl -we 'my $x = 0; sub foo { print "foo()\n"; die $x++ } $SIG{__DIE__} = \&foo; foo'
foo()
0 at -e line 1.

(Note that $SIG{__DIE__} has no effect here.)

Expected behavior

$ perl -we 'my $x = 0; sub foo { print "foo()\n"; die $x++ } $SIG{__DIE__} = \&foo; foo'
foo()
foo()
1 at -e line 1.

There should be exactly two calls to foo: One from foo in the main code, the other via $SIG{__DIE__}. It should not recurse further because as perldoc -v %SIG explains:

The __DIE__ handler is explicitly disabled during the call, so that you can die from a __DIE__ handler.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4