develooper Front page | perl.perl5.porters | Postings from May 2021

$^S value for try/catch blocks

Михаил Козачков
May 18, 2021 20:34
$^S value for try/catch blocks
Message ID:
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) { }


$^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)? Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About