File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,31 @@ Returns the L<Exception> object that the failure wraps.
56
56
put "$ex.^name(): $ex";
57
57
# OUTPUT: «X::AdHoc: Failed»
58
58
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
+
59
84
= head2 method Bool
60
85
61
86
Defined as:
You can’t perform that action at this time.
0 commit comments