develooper Front page | perl.datetime | Postings from July 2017

Re: How to check if a DateTime is invalid (again - but this timewithout using eval)?

Thread Previous | Thread Next
From:
Bill Moseley
Date:
July 5, 2017 16:27
Subject:
Re: How to check if a DateTime is invalid (again - but this timewithout using eval)?
Message ID:
CAKhN_m6eWGiQpmWcK60+tvf8mfooofHLz3QOQ2Zr=cvwLOpm=A@mail.gmail.com
Haven't those issues with eval been addressed in more recent versions of
Perl?

For example, in older Perls this used to reset $@, but now $@ is retained:

use strict;
use warnings;

sub Foo::DESTROY {
    print "in Foo Destroy\n";
    eval { 1 };
    print "Foo has \$@ as '$@'\n"
    return;
}

eval {
    my $foo = bless {}, 'Foo';
    die "BOOM\n";
};
print "eval with $@\n";


Returns:

in Foo Destroy
Foo has $@ as ''
eval with BOOM




On Wed, Jul 5, 2017 at 8:52 AM, Dave Rolsky <autarch@urth.org> wrote:

> On Wed, Jul 5, 2017 at 10:23 AM, Eric Brine <ikegami@adaelis.com> wrote:
>
>> On Wed, Jul 5, 2017 at 10:59 AM, Thomas (HFM) Wyant <
>> harryfmudd@comcast.net> wrote:
>>
>>> One of the edge cases with eval {} is ...
>>>
>>
>> All the edge cases are covered by the previously linked:
>> https://metacpan.org/pod/Try::Tiny#BACKGROUND
>>
>
> Yes, this is exactly why I would recommend always using Try::Tiny over
> plain eval.
>
> Cheers,
>
> Dave Rolsky
> http://blog.urth.org
> https://github.com/autarch
>
>


-- 
Bill Moseley
moseley@hank.org

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