Skip to content

Commit 0980a9c

Browse files
committed
Marks as unhandled a handled failure if fail is called on it refs #2632
1 parent 189e4a5 commit 0980a9c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

doc/Type/Failure.pod6

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,17 @@ the failure as handled.
163163
164164
Defined as:
165165
166+
multi sub fail(--> Nil)
166167
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)
168173
169174
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
171177
constructed from the concatenation of C<@text>. If the caller
172178
activated fatal exceptions via the pragma C<use fatal;>, the exception is
173179
thrown instead of being returned as a C<Failure>.
@@ -199,6 +205,24 @@ thrown instead of being returned as a C<Failure>.
199205
$result = copy-directory-tree('foo');
200206
say $result.exception; # OUTPUT: «This directory is forbidden: 'foo'␤»
201207
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
202226
203227
=end pod
204228

0 commit comments

Comments
 (0)