develooper Front page | perl.perl5.porters | Postings from January 2021

Re: Adding a try/catch syntax to Perl

Thread Previous | Thread Next
Philip R Brenan
January 22, 2021 18:34
Re: Adding a try/catch syntax to Perl
Message ID:
Please change *catch ($e)* to *catch $e *so that millions of people in the
decades to come do not have to waste thousands of man years of effort
struggling to correctly parse and place pointless parentheses when a small
amount of extra programming effort eftsoon could easily eradicate this evil
necessity in its entirety and thereby save us all a lot of time.  "Tempus
fugit".  "Ha una vita sola".

On Fri, Jan 22, 2021 at 5:02 PM Paul "LeoNerd" Evans <>

> I intend to add try/catch syntax. This has been one of the most
> frequently-requested of core syntax features - from both community
> sources like Freenode #perl and other core developers - so I do not
> anticipate this will be a contentious or debated idea.
> As many of the existing CPAN solutions all follow a very similar theme
> - including my own Syntax::Keyword::Try[1] - I expect I shall follow
> that pattern, and likewise do not anticipate that this will be
> considered controversial. Syntax::Keyword::Try has been the preferred
> module by Freenode #perl for a while now, and folks seem happy with it.
> I further intend it to be introduced as
>   use feature 'try';
> Towards this goal, I have created a module Feature::Compat::Try[2] to
> simplify migration. Existing authors can
>   use Feature::Compat::Try;
> in their current code, today, and import a configured version of
> Syntax::Keyword::Try which works on all Perl versions back to 5.16, and
> conforms exactly to the specification of the thing I want to add to
> core. (S:K:T additionally contains other features, experimental ideas,
> and past mistakes, that I do not intend to bring in at this time, hence
> the configuration).
> A brief summary, from its synopsis, is:
>   use Feature::Compat::Try;
>   sub foo
>   {
>      try {
>         attempt_a_thing();
>         return "success";
>      }
>      catch ($e) {
>         warn "It failed - $e";
>         return "failure";
>      }
>   }
> If anyone wishes to review in more detail the syntax and semantics,
> please read the documentation and unit-tests of this module. That is
> what I intend to implement exactly. You do not have to wait until I
> have a PR to actually implement it to do this - the earlier you do
> this, the better :)
> 1:
> 2:
> --
> Paul "LeoNerd" Evans
>      |
>  |


Phil <>

Philip R Brenan <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About