@@ -163,11 +163,17 @@ the failure as handled.
163
163
164
164
Defined as:
165
165
166
+ multi sub fail(--> Nil)
166
167
multi sub fail(*@text)
167
- multi sub fail(Exception $e)
168
+ multi sub fail(Exception:U $e --> Nil )
169
+ multi sub fail($payload --> Nil)
170
+ multi sub fail(|cap (*@msg) --> Nil)
171
+ multi sub fail(Failure:U $f --> Nil)
172
+ multi sub fail(Failure:D $fail --> Nil)
168
173
169
174
Exits the calling C < Routine > and returns a L < Failure|/type/Failure > object wrapping the
170
- exception C < $e > - or, for the C < *@text > form, an L < X::AdHoc|/type/X::AdHoc > exception
175
+ exception C < $e > - or, for the C < cap > or C < $payload > form, an
176
+ L < X::AdHoc|/type/X::AdHoc > exception
171
177
constructed from the concatenation of C < @text > . If the caller
172
178
activated fatal exceptions via the pragma C < use fatal; > , the exception is
173
179
thrown instead of being returned as a C < Failure > .
@@ -199,6 +205,24 @@ thrown instead of being returned as a C<Failure>.
199
205
$result = copy-directory-tree('foo');
200
206
say $result.exception; # OUTPUT: «This directory is forbidden: 'foo'»
201
207
208
+ If it's called with a generic C < Failure > , an ad-hoc undefined failure is
209
+ thrown; if it's a defined C < Failure > , it will be marked as unhandled.
210
+
211
+ = begin code
212
+ sub re-fail {
213
+ my $x = +"a";
214
+ unless $x.defined {
215
+ $x.handled = True;
216
+ say "Something has failed in \$x ", $x.^name;
217
+ # OUTPUT: «Something has failed in $x Failure»
218
+ fail($x);
219
+ return $x;
220
+ }
221
+ }
222
+
223
+ my $x = re-fail;
224
+ say $x.handled; # OUTPUT: «False»
225
+ = end code
202
226
203
227
= end pod
204
228
0 commit comments