Skip to content

$SIG{__DIE__} handler doesn't work when called explicitly #22984

Open
@mauke

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions