You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Language/exceptions.pod6
+22-14Lines changed: 22 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -63,9 +63,13 @@ To handle all exceptions use a C<default> statement.
63
63
}
64
64
65
65
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:
67
72
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:
69
73
70
74
die "something went wrong ...";
71
75
@@ -75,33 +79,37 @@ As exceptions interrupt control flow it's important to say that all the code fol
75
79
}
76
80
77
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
+
78
87
say "This won't be said.";
79
88
80
-
89
+
81
90
Output:
82
91
83
92
something went wrong ...
84
93
85
-
To ensure some code gets executed I<after>C<CATCH> block use C<LEAVE> block:
94
+
Compare with this one:
86
95
87
-
die "something went wrong ...";
88
-
89
96
CATCH {
90
-
default { .Str.say; }
91
-
}
92
97
93
-
say "This won't be said.";
98
+
CATCH {
99
+
default { .Str.say; }
100
+
}
94
101
102
+
die "something went wrong ...";
95
103
96
-
LEAVE {
97
-
say "I am saying farewell!";
98
104
}
99
105
100
-
106
+
say "Hi! I am at the upper block!";
107
+
101
108
Output:
102
109
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.
0 commit comments