Skip to content

Commit 81df0c3

Browse files
committed
Revise and explain examples
Closes #2468 after most of the work has been done by @uzluisf
1 parent 9900c9a commit 81df0c3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

doc/Language/exceptions.pod6

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,24 @@ how to return control back to where the exception originated.
124124
X<|try blocks>
125125
=head1 C<try> blocks
126126
127-
A C<try> block is a normal block with the L<C<use fatal>
128-
pragma|/language/pragmas#index-entry-fatal-fatal> turned on and an
129-
implicit C<CATCH> block that drops the exception, which means you can
130-
use it to contain them. Caught exceptions are stored inside the C<$!>
131-
variable, which holds a value of type C<Exception>.
127+
A C<try> block is a normal block which implicitly turns on the
128+
L<C<use fatal> pragma|/language/pragmas#index-entry-fatal-fatal> and
129+
includes an implicit C<CATCH> block that drops the exception, which
130+
means you can use it to contain them. Caught exceptions are stored
131+
inside the C<$!> variable, which holds a value of type C<Exception>.
132132
133-
=begin code
133+
A normal block like this one will simply fail:
134+
135+
=for code
134136
{
135137
my $x = +"a";
136138
say $x.^name;
137139
} # OUTPUT: «Failure␤»
138140
141+
However, a C<try> block will contain the exception and put it into the
142+
C<$!> variable:
143+
144+
=begin code
139145
try {
140146
my $x = +"a";
141147
say $x.^name;
@@ -146,7 +152,7 @@ say $!.^name; # OUTPUT: «X::Str::Numeric␤»
146152
=end code
147153
148154
Any exception that is thrown in such a block will be caught by a
149-
C<CATCH> block, either implicit provided by the user. In the latter
155+
C<CATCH> block, either implicit or provided by the user. In the latter
150156
case, any unhandled exception will be rethrown. If you choose not to
151157
handle the exception, they will be contained by the block.
152158

0 commit comments

Comments
 (0)