From: Yuval Kogman Date: Tue, 23 Feb 2010 11:07:06 +0000 (+0100) Subject: Clarify $_/$@ distinction X-Git-Tag: Try-Tiny-0.05~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2dc642499238e6dfa5035f0b3bf2d473d56dda80;p=p5sagit%2FTry-Tiny.git Clarify $_/$@ distinction --- diff --git a/lib/Try/Tiny.pm b/lib/Try/Tiny.pm index 9b99f91..adf3a69 100644 --- a/lib/Try/Tiny.pm +++ b/lib/Try/Tiny.pm @@ -148,7 +148,7 @@ Try::Tiny - minimal try/catch with proper localization of $@ try { die "foo"; } catch { - warn "caught error: $_"; + warn "caught error: $_"; # not $@ }; # just silence errors @@ -217,6 +217,9 @@ If there was an error and the second subroutine was given it will be invoked with the error in C<$_> (localized) and as that block's first and only argument. +C<$@> does B contain the error. Inside the C block it has the same +value it had before the C block was executed. + Note that the error may be false, but if that happens the C block will still be invoked. @@ -232,9 +235,10 @@ with this code reference. catch { ... } -Inside the catch block the previous value of C<$@> is still available for use. -This value may or may not be meaningful depending on what happened before the -C, but it might be a good idea to preserve it in an error stack. +Inside the catch block the caught error is stored in C<$_>, while previous +value of C<$@> is still available for use. This value may or may not be +meaningful depending on what happened before the C, but it might be a good +idea to preserve it in an error stack. For code that captures C<$@> when throwing new errors (i.e. L), you'll need to do: