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:
Karen Etheridge
Date:
June 27, 2020 17:48
Subject:
Re: Thoughts in the direction of a core try/catch syntax
Message ID:
CAPJsHfBaAhXPb=sYRYzWX+ymrr2rbyPrUPOVYWw1_LN+eMA5hA@mail.gmail.com
On Sat, Jun 27, 2020 at 5:39 AM Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
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" }
>

TBH I'd be content with just
...
try {
 ...
}
catch my $e {
  if ($e isa X::SomeException) { ... }
  elsif ($e =~ m/^Cannot do a thing/) { ... }
  else { ... }
}
finally {
  ...
}

..but I'm not usually the most imaginative when it comes to new syntax, and
the smartmatch debacle showed us that there are many wrong ways to do it :)

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