Skip to content

Commit a5f98bd

Browse files
authored
Merge pull request #876 from melezhik/master
Exceptions handlers and enclosing blocks.
2 parents 8b59639 + 4a4c9e3 commit a5f98bd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

doc/Language/exceptions.pod6

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,55 @@ To handle all exceptions use a C<default> statement.
6262
}
6363
}
6464
65+
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:
72+
73+
74+
die "something went wrong ...";
75+
76+
CATCH {
77+
# will definitely catch all the exception
78+
default { .Str.say; }
79+
}
80+
81+
# 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+
87+
say "This won't be said.";
88+
89+
90+
Output:
91+
92+
something went wrong ...
93+
94+
Compare with this one:
95+
96+
CATCH {
97+
98+
CATCH {
99+
default { .Str.say; }
100+
}
101+
102+
die "something went wrong ...";
103+
104+
}
105+
106+
say "Hi! I am at the outer block!";
107+
108+
Output:
109+
110+
Hi! I am at the outer block!
111+
112+
See also "Resuming of Exceptions" to know who to return control to the statement following the statement that threw the exception.
113+
65114
=head1 X<C<try>|try blocks> blocks
66115
67116
To contain an exception use a C<try> block. Any exception that is thrown in

0 commit comments

Comments
 (0)