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:
Zefram
Date:
July 3, 2017 17:10
Subject:
Re: How to check if a DateTime is invalid (again - but this timewithout using eval)?
Message ID:
20170703171032.GM7189@fysh.org
Eric Brine wrote:
>On Mon, Jul 3, 2017 at 11:11 AM, Thomas Klausner <domm@cpan.org> wrote:
>> I personally don't like Try::Tiny, because it changes how 'return' works
>> inside an eval (well, try)
>
>What difference is there?

I think domm is actually thinking of TryCatch there.  Inside an eval,
or Try::Tiny's try, a return expression returns from the eval/try.
Inside TryCatch's try, a return expression ignores the try scope and
returns from whatever it would have returned from without it, usually
from the enclosing subroutine.

$ perl -lwe 'sub z { eval { return 123 }; return 456; } print z()'
456
$ perl -MTry::Tiny -lwe 'sub z { try { return 123; }; return 456; } print z()'
456
$ perl -MTryCatch -lwe 'sub z { try { return 123; } return 456; } print z()'
123

-zefram

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