develooper Front page | perl.perl5.porters | Postings from June 2016

Re: Confused by eval behavior

Thread Previous | Thread Next
John Siracusa
June 27, 2016 18:37
Re: Confused by eval behavior
Message ID:
This new example looks even more like a bug:

(Code also appears below.)



use strict;
use warnings;

package Dummy;

sub new { bless {}, shift }

sub throw_error {
die 'Died in throw_error';

eval { };

package DummyContainer;

sub new { bless {}, shift }

sub add_things {
my ($self, $things) = @_;

package main;

use Test::More tests => 1;

eval {
my $dummy = Dummy->new();

my $dummy_container = DummyContainer->new([]);



like($@, qr/Died in throw_error/, 'exception thrown in eval is visible');


On Fri, Jun 24, 2016 at 3:09 PM, Zefram <> wrote:

> Aristotle Pagaltzis wrote:
> >Does this thread constitute a case where it matters sufficiently to
> >change it?
> Yes.  To have a reliable $@ value immediately after eval is important,
> and the programmer can't be expected to anticipate which things might
> be mortalised and so capable of clobbering it.
> However, one doesn't necessarily have to solve this by generally changing
> the timing of temp freeing.  Another option is to save and restore $@
> around temp freeing.  It's not obvious which of these would perform
> better.  There may also be some option of changing timing just for eval,
> which if possible would almost certainly have the best performance.
> -zefram

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