@@ -124,18 +124,24 @@ how to return control back to where the exception originated.
124
124
X < |try blocks >
125
125
= head1 C < try > blocks
126
126
127
- A C < try > block is a normal block with the L < C < use fatal >
128
- pragma|/language/pragmas#index-entry-fatal-fatal > turned on and an
129
- implicit C < CATCH > block that drops the exception, which means you can
130
- use it to contain them. Caught exceptions are stored inside the C < $! >
131
- variable, which holds a value of type C < Exception > .
127
+ A C < try > block is a normal block which implicitly turns on the
128
+ L < C < use fatal > pragma|/language/pragmas#index-entry-fatal-fatal> and
129
+ includes an implicit C < CATCH > block that drops the exception, which
130
+ means you can use it to contain them. Caught exceptions are stored
131
+ inside the C < $! > variable, which holds a value of type C < Exception > .
132
132
133
- = begin code
133
+ A normal block like this one will simply fail:
134
+
135
+ = for code
134
136
{
135
137
my $x = +"a";
136
138
say $x.^name;
137
139
} # OUTPUT: «Failure»
138
140
141
+ However, a C < try > block will contain the exception and put it into the
142
+ C < $! > variable:
143
+
144
+ = begin code
139
145
try {
140
146
my $x = +"a";
141
147
say $x.^name;
@@ -146,7 +152,7 @@ say $!.^name; # OUTPUT: «X::Str::Numeric»
146
152
= end code
147
153
148
154
Any exception that is thrown in such a block will be caught by a
149
- C < CATCH > block, either implicit provided by the user. In the latter
155
+ C < CATCH > block, either implicit or provided by the user. In the latter
150
156
case, any unhandled exception will be rethrown. If you choose not to
151
157
handle the exception, they will be contained by the block.
152
158
0 commit comments