develooper Front page | perl.perl5.porters | Postings from March 2008

Re: local $@ has an unwanted side effect

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
March 21, 2008 09:48
Subject:
Re: local $@ has an unwanted side effect
Message ID:
20080321164811.GC14063@penkwe.pair.com
On Fri, Mar 21, 2008 at 05:27:04PM +0100, Abigail wrote:
> Inspecting $@ to check whether an eval die()d is wrong. It can
> trigger both false positives, and false negatives:
> 
> [snip]
> 
> The correct way of checking whether an eval failed is to check its return
> value:
> 
> [snip]

The documentation for eval should probably be updated...

perldoc -f eval

  [...]

  If there is a syntax error or runtime error, or a die statement is
  executed, an undefined value is returned by eval, and $@ is set to the
  error message. If there was no error, $@ is guaranteed to be a null
  string.  [...]

  [...]

    # make divide-by-zero nonfatal
    eval { $answer = $a / $b; }; warn $@ if $@;

  [etc.]

Ronald

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About