Skip to content

Commit 91e7c16

Browse files
committed
document Failure
1 parent b7cae64 commit 91e7c16

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

lib/Failure.pod

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
=begin pod
2+
3+
=TITLE class Failure
4+
5+
class Failure { }
6+
7+
A C<Failure> is a I<soft> or I<unthrown> exception, usually generated by
8+
calling C<&fail>. It acts as a wrapper around an L<Exception> object.
9+
10+
Sink (void) context causes a Failure to throw, i.e. turn into a normal
11+
exception.
12+
13+
Checking a Failure for truth (with the C<Bool> method) or definedness (with
14+
the C<defined> method) marks the failure as handled, and causes it not to
15+
throw in sink context anymore.
16+
17+
You can call the C<handled> method to check if a failure has been handled.
18+
19+
Calling methods on unhandled failures propagates the failure. The
20+
specification says the result is another C<Failure>, in Rakudo it causes the
21+
failure to throw.
22+
23+
=head1 Methods
24+
25+
=head2 handled
26+
27+
method handled(Failure:D:) returns Bool:D
28+
29+
Returns C<True> for handled failures, C<False> otherwise.
30+
31+
=head2 exception
32+
33+
method handled(Failure:D:) returns Exception
34+
35+
Returns the L<Exception> object that the failure wraps.
36+
37+
=head2 Bool
38+
39+
multi method Bool(Failure:D:) returns Bool:D
40+
41+
Returns C<False>, and marks the failure as handled.
42+
43+
=head2 defined
44+
45+
multi method defined(Failure:D:) returns Bool:D
46+
47+
Returns C<False> (failures are officially undefined), and marks
48+
the failure as handled.
49+
50+
=end pod

0 commit comments

Comments
 (0)