Skip to content

Commit 81f35fd

Browse files
authored
Document exploding sunk Proc trap
There were a few RTs involving.
1 parent 9302e6f commit 81f35fd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/Language/traps.pod6

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,25 @@ The nice thing about the distinction here is that it gives the developer the
404404
option of passing pairs as either named or positional arguments, which can be
405405
handy in various instances.
406406
407+
=head1 Exception Handling
408+
409+
=head2 Sunk C<Proc>
410+
411+
Some methods return a L<Proc> object. If it represents a failed process, C<Proc> itself
412+
won't be exception-like, but B<sinking it> will cause an L<X::Proc::Unsuccessful>
413+
exception to be thrown. That means this construct will throw, despite the C<try> in place:
414+
415+
try run("perl6", "-e", "exit 42");
416+
say "still alive";
417+
# OUTPUT: The spawned process exited unsuccessfully (exit code: 42)
418+
419+
This is because C<try> receives a C<Proc> and returns it, at which point it sinks and
420+
throws. Explicitly sinking it inside the C<try> avoids the issue:
421+
422+
try sink run("perl6", "-e", "exit 42");
423+
say "still alive";
424+
# OUTPUT: still alive
425+
407426
=end pod
408427

409428
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)