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:
Binarus
Date:
July 6, 2017 06:37
Subject:
Re: How to check if a DateTime is invalid (again - but this timewithout using eval)?
Message ID:
13642f93-497b-cbec-ca3d-8fd20b24787c@binarus.de
On 03.07.2017 13:09, Rick Measham wrote:
> I'm not sure what you mean by 'local DIE handlers'. Are you talking
> about defining a local $SIG{__DIE__} ?
> 

Exactly. Most examples I saw are doing this, but since I don't catch any
signals anywhere else in my application, I think I don't need it. On the
other hand, you never know about other libraries / modules, so I
probably will do it nevertheless. After all, it won't hurt (to my best
knowledge).

> I've been out of perl for a couple of years, but surely you should just
> use eval{} ?
> 
> 
> $dt = eval { $parser->parse( $input );};
> 
> if( $@ ){
> 
>    echo "Unable to parse your date ($input)\n";
> 
>    exit;
> 
> }
> 
> echo "Your date is $dt\n";
> 
> 
> - Rick
> 

Yes, I'll follow everybody's advice and use eval, but I won't use $@.
The only thing I must know is if DateTime -> new() inside the eval has
died or not, so I'll just test if the eval return undef.

Thanks for your help!

Regards,

Binarus

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