Skip to content

Commit 36648dc

Browse files
committed
adjustment after talk with people by IRC
1 parent c9918db commit 36648dc

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

doc/Language/exceptions.pod6

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ To handle all exceptions use a C<default> statement.
6363
}
6464
6565
66-
## CATCH block and the following code
66+
## Exceptions handlers and enclosing blocks.
67+
68+
After a CATCH has handled the exception, the block enclosing the CATCH is left.
69+
70+
In other words even exception is handled successfully, the I<rest of code> in the enclosing block will never be executed
71+
as enclosing block gets left immediately:
6772
68-
As exceptions interrupt control flow it's important to say that all the code following after C<CATCH> block will never be executed, even though exception is handled successfully:
6973
7074
die "something went wrong ...";
7175
@@ -75,33 +79,37 @@ As exceptions interrupt control flow it's important to say that all the code fol
7579
}
7680
7781
# but this line will be never reached
82+
# as once default exception handler
83+
# gets executed
84+
# a enclosing block - mainline of the program
85+
# will be left immediately
86+
7887
say "This won't be said.";
7988
80-
89+
8190
Output:
8291
8392
something went wrong ...
8493
85-
To ensure some code gets executed I<after> C<CATCH> block use C<LEAVE> block:
94+
Compare with this one:
8695
87-
die "something went wrong ...";
88-
8996
CATCH {
90-
default { .Str.say; }
91-
}
9297
93-
say "This won't be said.";
98+
CATCH {
99+
default { .Str.say; }
100+
}
94101
102+
die "something went wrong ...";
95103
96-
LEAVE {
97-
say "I am saying farewell!";
98104
}
99105
100-
106+
say "Hi! I am at the upper block!";
107+
101108
Output:
102109
103-
something went wrong ...
104-
I am saying farewell!
110+
Hi! I am at the upper block!
111+
112+
See also "Resuming of Exceptions" to know who to return control to the statement following the statement that threw the exception.
105113
106114
=head1 X<C<try>|try blocks> blocks
107115

0 commit comments

Comments
 (0)