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

Re: local $@ has an unwanted side effect

Thread Previous | Thread Next
Ronald J Kimball
March 21, 2008 09:48
Re: local $@ has an unwanted side effect
Message ID:
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 $@;



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About