4
4
5
5
= SUBTITLE Using exceptions in Perl 6
6
6
7
- Exceptions in Perl 6 are objects that hold information about errors. An error
8
- can be, for example, the unexpected receiving of data or a network connection no
9
- longer available, or a missing file. The information that an exception objects
10
- store is, for instance, a human-readable message about the error condition, the
11
- backtrace of the raising of the error, and so on.
7
+ Exceptions in Perl 6 are objects that hold information about errors. An
8
+ error can be, for example, the unexpected receiving of data or a network
9
+ connection no longer available, or a missing file. The information that
10
+ an exception objects store is, for instance, a human-readable message
11
+ about the error condition, the backtrace of the raising of the error,
12
+ and so on.
12
13
13
14
All built-in exceptions inherit from L < Exception > , which provides some basic
14
15
behavior, including the storage of a backtrace and an interface for the
@@ -123,11 +124,11 @@ how to return control back to where the exception originated.
123
124
X < |try blocks >
124
125
= head1 C < try > blocks
125
126
126
- A C < try > block is a normal block with the
127
- L < C < use fatal > pragma|/language/pragmas#index-entry-fatal-fatal>
128
- turned on and an implicit C < CATCH > block that drops the exception, which
129
- means you can use it to contain them. If the exception is caught, then it's
130
- stored inside the C < $! > variable which holds a value of type C < Exception > .
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 > .
131
132
132
133
= begin code
133
134
{
@@ -144,10 +145,10 @@ if $! { say "Something failed!" } # OUTPUT: «Something failed!»
144
145
say $!.^name; # OUTPUT: «X::Str::Numeric»
145
146
= end code
146
147
147
- Any exception that is thrown in such a block will be caught by the implicit
148
- C < CATCH > block or a C < CATCH > block provided by the user. In the latter case, any
149
- unhandled exception will be rethrown. If you choose not to handle the exception,
150
- they will be contained by the block.
148
+ 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
150
+ case, any unhandled exception will be rethrown. If you choose not to
151
+ handle the exception, they will be contained by the block.
151
152
152
153
= begin code
153
154
try {
0 commit comments