Mailing List Archive

$^S value for try/catch blocks
use strict;
use warnings;

use feature 'try';
use feature 'say';

no warnings 'experimental';

$SIG{__DIE__} = sub {
say "\$^S: $^S";
};

try {
die 'I have to go';
}
catch ($e) { }

exit;

Output:
$^S: 1

Whereas pervar says:

>
> $^S Current state of the interpreter.
>
> $^S State
> --------- -------------------------------------
> undef Parsing module, eval, or main program
> true (1) Executing an eval
> false (0) Otherwise
>
> The first state may happen in $SIG{__DIE__} and $SIG{__WARN__} handlers.
>
> The English name $EXCEPTIONS_BEING_CAUGHT is slightly misleading, because the "undef" value does not indicate whether exceptions are being caught, since
> compilation of the main program does not catch exceptions.
>
> This variable was added in Perl 5.004.



It means that "die" call occured in a eval, but try/catch blocks aren't
eval blocks (in the usual sense).

May be it make sense to add some explanations to pod about it and also
fix the $^S value when die happens in try/catch blocks (especially try)?