Skip to content

Commit

Permalink
Revise and explain examples
Browse files Browse the repository at this point in the history
Closes #2468 after most of the work has been done by @uzluisf
  • Loading branch information
JJ committed Dec 2, 2018
1 parent 9900c9a commit 81df0c3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions doc/Language/exceptions.pod6
Expand Up @@ -124,18 +124,24 @@ how to return control back to where the exception originated.
X<|try blocks>
=head1 C<try> blocks
A C<try> block is a normal block with the L<C<use fatal>
pragma|/language/pragmas#index-entry-fatal-fatal> turned on and an
implicit C<CATCH> block that drops the exception, which means you can
use it to contain them. Caught exceptions are stored inside the C<$!>
variable, which holds a value of type C<Exception>.
A C<try> block is a normal block which implicitly turns on the
L<C<use fatal> pragma|/language/pragmas#index-entry-fatal-fatal> and
includes an implicit C<CATCH> block that drops the exception, which
means you can use it to contain them. Caught exceptions are stored
inside the C<$!> variable, which holds a value of type C<Exception>.
=begin code
A normal block like this one will simply fail:
=for code
{
my $x = +"a";
say $x.^name;
} # OUTPUT: «Failure␤»
However, a C<try> block will contain the exception and put it into the
C<$!> variable:
=begin code
try {
my $x = +"a";
say $x.^name;
Expand All @@ -146,7 +152,7 @@ say $!.^name; # OUTPUT: «X::Str::Numeric␤»
=end code
Any exception that is thrown in such a block will be caught by a
C<CATCH> block, either implicit provided by the user. In the latter
C<CATCH> block, either implicit or provided by the user. In the latter
case, any unhandled exception will be rethrown. If you choose not to
handle the exception, they will be contained by the block.
Expand Down

0 comments on commit 81df0c3

Please sign in to comment.