develooper Front page | perl.perl5.porters | Postings from June 2020

Re: Thoughts in the direction of a core try/catch syntax

Thread Previous | Thread Next
From:
Andrew Hewus Fresh
Date:
June 27, 2020 20:05
Subject:
Re: Thoughts in the direction of a core try/catch syntax
Message ID:
20200627200537.GD74210@us.holligan.net
On Sat, Jun 27, 2020 at 01:39:27PM +0100, Paul "LeoNerd" Evans wrote:
> How would you see rewriting that in a hypothetical core 'try'? I
> suggest for example:
> 
>   use feature 'try';
> 
>   try {
>     somefunc();
>   }
>   catch my $e (isa X::SomeException) { say "Red" }
>   catch my $e (=~ m/^Cannot do a thing /) { say "Blue" }
> 
> Which is non-ideal due to multiple `my $e` and those dangling binary
> operators `isa` and `=~` just starting the parens there. They look a
> bit ugly IMHO.
> 
> Can we find better?


As mentioned on IRC, I don't really care about try/catch, but do wonder
how it will interact with $SIG{__DIE__} and $^S.

Most the annoyances I've had with eval would not exist if $SIG{__DIE__}
from the outside of the eval didn't make it inside and a few more would
have been avoided if $^S would increment as eval gets nested.

I do, however, like the idea of making it easier to catch specific
exceptions rather than having to re-raise if it's not one I care about.

l8rZ,
-- 
andrew - http://afresh1.com

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots. So far, the Universe is
winning."             -- Rich Cook

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