summaryrefslogtreecommitdiff
path: root/pod/perlsyn.pod
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2021-02-14 13:59:23 +0000
committerPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2021-02-14 13:59:23 +0000
commit397e6c111f3e1ef0f2fb7475e9379dccda9fca6a (patch)
tree89fa6c9610cf6a8cb8e8319c3470eb13ed65cf9a /pod/perlsyn.pod
parent06ea6db364113525b11334d875834cb5ded50dba (diff)
downloadperl-397e6c111f3e1ef0f2fb7475e9379dccda9fca6a.tar.gz
Document and test that do {try/catch} behaves as expected; yielding the final expression value
Diffstat (limited to 'pod/perlsyn.pod')
-rw-r--r--pod/perlsyn.pod16
1 files changed, 16 insertions, 0 deletions
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index 8649d46127..8e3045656b 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -650,6 +650,22 @@ expression inside the C<try> block will make its entire containing function
return - this is in contrast to its behaviour inside an C<eval> block, where
it would only make that block return.
+Like other control-flow syntax, C<try> and C<catch> will yield the last
+evaluated value when placed as the final statement in a function or a C<do>
+block. This permits the syntax to be used to create a value. In this case
+remember not to use the C<return> expression, or that will cause the
+containing function to return.
+
+ my $value = do {
+ try {
+ get_thing(@args);
+ }
+ catch ($e) {
+ warn "Unable to get thing - $e";
+ $DEFAULT_THING;
+ }
+ };
+
This syntax is currently experimental and must be enabled with
C<use feature 'try'>. It emits a warning in the C<experimental::try> category.