* Abelard <
abelard...@gmail.com> [2016-09-12 21:12]:
> What's the issue if $old_die_handler uses goto instead of die? This is
> a worry about the inifinite loop again, or something else?
There is this bit in perlvar:
When a "__DIE__" hook routine returns, the exception processing
continues as it would have in the absence of the hook, unless the
hook routine itself exits via a "goto &sub", a loop exit, or
a "die()".
So if the old die handler uses goto, it abandons the exception, but if
you call it regularly from within another die handler, then the old die
handler is Just Another Function, and when it does its goto, it doesn’t
mean anything special.
So in that case, your die handler has to do the goto which abandons the
exception; after which it doesn’t matter what the old die handler does.
At least, that’s my understanding of the documentation. In testing I’ve
not succeeded in making an exception go away, so far.
> I was trying to identify the problem with this code but it seems to be
> working okay:
Yes, that code should be OK. Because _old_die2 dies, you can just call
it instead of using goto, which allows the recursion check to find your
die handler on the stack, so it won’t try to call you again, and all is
well in the world.
So if you know the old handler always dies, you just call it normally.
And if you know it always does goto, you use goto.
That’s good enough for you case.
The remaining question is how to chain die handlers when you *don’t*
know what it will do, *or*, when the old die handler *sometimes* dies
but other times uses goto. You would need to both remove your stack
frame (so the handler can use goto) and leave it (so the handler can
die) at the same time – which is a contradiction. (Again, based on my
understanding; I have not been able to confirm this in testing.)
I don’t see a good answer for that, only the ones I mentioned (scope
guard in @_ to change $SIG{__DIE__}, or a manual recursion check).
But you don’t have that situation anyway, so you’re fine.