Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #1773 and adds clarification
  • Loading branch information
JJ committed Jun 8, 2019
1 parent 69ea20e commit e24ef2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
10 changes: 4 additions & 6 deletions doc/Type/Exception.pod6
Expand Up @@ -43,15 +43,13 @@ an exception itself.
Defined as:
method backtrace(Exception:D: --> Backtrace:D)
method backtrace(Exception:D:)
Returns the backtrace associated with the exception. Only makes sense
on exceptions that have been thrown at least once.
Returns the backtrace associated with the exception or an empty string if there
is none. Only makes sense on exceptions that have been thrown at least once.
try die "Something bad happened";
if ($!) {
print $!.backtrace;
}
with $! { .backtrace.print ; }
=head2 method throw
Expand Down
21 changes: 11 additions & 10 deletions doc/Type/X/AdHoc.pod6
Expand Up @@ -10,9 +10,9 @@ class X::AdHoc is Exception { }
C<X::AdHoc> is the type into which objects are wrapped if they are
thrown as exceptions, but don't inherit from L<Exception|/type/Exception>.
Its benefit over returning non-C<Exception> objects is that it gives
access to all the methods from class L<Exception|/type/Exception>, like C<backtrace>
and C<rethrow>.
Its benefit over returning non-C<Exception> objects is that it gives access to
all the methods from class L<Exception|/type/Exception>, like C<backtrace> and
C<rethrow>.
You can obtain the original object with the C<payload> method.
Expand All @@ -22,13 +22,14 @@ You can obtain the original object with the C<payload> method.
print "Got HTTP code ",
$!.payload[0], # 404
" and backtrace ",
$!.backtrace;
Note that young code will often be prototyped using C<X::AdHoc> and
then later be revised to use more specific subtypes of C<Exception>.
As such it is usually best not to explicitly rely on receiving an
C<X::AdHoc> – in many cases using the string returned by the
C<.message> method, which all C<Exception>s must have, is preferable.
$!.backtrace.Str;
Note that young code will often be prototyped using C<X::AdHoc> and then later
be revised to use more specific subtypes of C<Exception>. As such it is usually
best not to explicitly rely on receiving an C<X::AdHoc> – in many cases using
the string returned by the C<.message> method, which all C<Exception>s must
have, is preferable. Please note that we need to explicitly call C<.Str> to
stringify the backtrace correctly.
=head1 Methods
Expand Down

0 comments on commit e24ef2b

Please sign in to comment.