Skip to content

Commit 457be16

Browse files
authored
Document Failure.self
Rakudo impl: rakudo/rakudo@0a100825dd Tests: Raku/roast@5bdb393ea9
1 parent 057c651 commit 457be16

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

doc/Type/Failure.pod6

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ Returns the L<Exception> object that the failure wraps.
5656
put "$ex.^name(): $ex";
5757
# OUTPUT: «X::AdHoc: Failed␤»
5858
59+
=head2 method self
60+
61+
Defined as:
62+
63+
method exception(Failure:D: --> Failure:D)
64+
65+
If the invocant is a L<handled> C<Failure>, returns it as is.
66+
If not not handled, throws its L<Exception>. Since
67+
L<Mu> type L«provides C<.self>|/type/Mu#method_self» for every
68+
class, calling this method is a handy way to explosively
69+
filter out Failures:
70+
71+
my $num1 = '♥'.Int;
72+
# $num1 now contains a Failure object, which may not be desirable
73+
74+
my $num2 = '♥'.Int.self;
75+
# .self method call on Failure causes an exception to be thrown
76+
77+
my $num3 = '42'.Int.self;
78+
# Int type has a .self method, so here $num3 has `42` in it
79+
80+
(my $stuff = '♥'.Int).so;
81+
say $stuff.self; # OUTPUT: «(HANDLED) Cannot convert string to number…»
82+
# Here, Failure is handled, so .self just returns it as is
83+
5984
=head2 method Bool
6085
6186
Defined as:

0 commit comments

Comments
 (0)