git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Nick <oinksocket@letterboxes.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	git@vger.kernel.org, "Petr Baudis" <pasky@suse.cz>,
	"Alex Riesen" <raa.lkml@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [1.8.0] perl/Git.pm: moving away from using Error.pm module
Date: Mon, 21 Feb 2011 13:12:44 +0100	[thread overview]
Message-ID: <201102211312.48333.jnareb@gmail.com> (raw)
In-Reply-To: <4D624632.80904@letterboxes.org>

On Mon, 21 Feb 2011, Nick wrote:
> On 21/02/11 07:20, Junio C Hamano wrote:

> > If we are going to change things so that everybody uses a
> > more traditional "eval {}; if ($@) { ... }", it would be a welcome change
> > from my point of view.
> 
> A small aside - note the "Dangers of using $@" described here:
> 
>   http://www.socialtext.net/perl5/exception_handling
> 
> To paraphrase, this:
> 
>   eval { stuff ; 1} or do { handle_exception };
> 
> is marginally safer than:
> 
>   eval { stuff }; if (defined $@) { handle_exception }

Important note: it is "if ($@)", not "if (defined $@)":

  If there was no error, $@ is guaranteed to be a null string.
                                                  ^^^^^^^^^^^

It is empty string, not undef.

> because it is possible that $@ can be modified (say, by a DESTROY method) before
> the if clause sees it.  The former idiom does not stop that, it just means your
> exception handler is executed reliably.
> 
> Normally it is not a problem, but this is still something worth knowing.

Or better use Try::Tiny, which takes care of this and more

  use Try::Tiny;
  try { stuff  } catch { handle_exception };

-- 
Jakub Narebski
Poland

  reply	other threads:[~2011-02-21 12:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-20 22:46 [1.8.0] perl/Git.pm: moving away from using Error.pm module Jakub Narebski
2011-02-21  7:20 ` Junio C Hamano
2011-02-21  9:31   ` Jakub Narebski
2011-02-21 11:02   ` Nick
2011-02-21 12:12     ` Jakub Narebski [this message]
2011-02-21 12:31     ` Ævar Arnfjörð Bjarmason
2011-04-15 23:35       ` Avner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201102211312.48333.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=oinksocket@letterboxes.org \
    --cc=pasky@suse.cz \
    --cc=raa.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).