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:
Eric Brine
Date:
July 11, 2017 16:09
Subject:
Re: How to check if a DateTime is invalid (again - but this timewithout using eval)?
Message ID:
CALJW-qEHV9pNoGRgFWDt4CM65uptwpG0oi50OEucW9m++ooi5w@mail.gmail.com
Simpler:

if (!eval {
    # try
    ...
    return 1; # ok
}) {
    # catch
    ...
}

On Jul 11, 2017 12:06 PM, "Paul Hoffman" <nkuitse@nkuitse.com> wrote:

On Mon, Jul 10, 2017 at 09:44:15PM +0100, Zefram wrote:
> Thomas (HFM) Wyant wrote:
> >One of the edge cases with eval {} is the possibility that $@ gets
> >clobbered before you get your hands on it.
>
> The possibility of it being clobbered by a destructor was fixed in 5.14.
> (Destructors that do this are considered buggy, for pre-5.14 perls,
> and are individually easy to fix, so the problem is still manageable on
> those perl versions.)

And in perl < 5.14 you can work around it easily enough:

    my $ok;
    eval {
        ...
        $ok = 1;
    };
    if ($ok) {
        ...
    }

Paul.

--
Paul Hoffman <nkuitse@nkuitse.com>

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