Skip to content

Commit

Permalink
Documenting LEAVE trap, closes #3148
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Aug 5, 2020
1 parent beb441c commit 6de783d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/Language/traps.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,25 @@ sub explicitly-return-ret () {
}
=end code
=head2 C<LEAVE> needs explicit return from a sub to run
As the documentation for the
L<C<LEAVE> phaser indicates|/language/phasers#index-entry-Phasers__LEAVE-LEAVE>
C<LEAVE> runs when a block is exited, "... except when the program exits
abruptly". That is, unlike C<END>, it's going to be invoked only if the block
actually returns in an orderly way. This is why:
=for code
sub a() { LEAVE say "left"; exit 1 }; # No output, it will simply exit
will not run the C<LEAVE> code, since technically it's not returning. On the
other hand, L<C<END>|/language/phasers#END> is a program execution phaser and
will run no matter what
=for code
sub a() {
END say "Begone"; exit 1
}; a; # OUTPUT: «Begone␤»
=head1 Input and output
Expand Down

0 comments on commit 6de783d

Please sign in to comment.