File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,55 @@ To handle all exceptions use a C<default> statement.
62
62
}
63
63
}
64
64
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
+
65
114
= head1 X < C < try > |try blocks> blocks
66
115
67
116
To contain an exception use a C < try > block. Any exception that is thrown in
You can’t perform that action at this time.
0 commit comments