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:
Dave Rolsky
Date:
July 5, 2017 16:43
Subject:
Re: How to check if a DateTime is invalid (again - but this timewithout using eval)?
Message ID:
CAHKw1MKg==onfQi1uj5pFWYL8ubaGzUxBakUonKAjJOOYjjVCg@mail.gmail.com
On Wed, Jul 5, 2017 at 11:27 AM, Bill Moseley <moseley@hank.org> wrote:

> 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
>
>
Well, that's one issue, but there are others, for example $@ being set to a
false value. I also appreciate the semantic clarity of try/catch.


Cheers,

Dave Rolsky
http://blog.urth.org
https://github.com/autarch

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