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

Re: Pre-RFC: try/catch/finally and generic finally blocks

Thread Previous | Thread Next
From:
Yuki Kimoto
Date:
December 20, 2021 23:55
Subject:
Re: Pre-RFC: try/catch/finally and generic finally blocks
Message ID:
CAExogxNmNmoDsxKhe=zqWc6rzPyREqdSxTgLqTu7LUzykGwDKg@mail.gmail.com
2021-12-17 7:23 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> On Tue, 19 Oct 2021 19:25:04 +0100
> "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:
>
> > Using the same internals that makes them work it would be quite easy
> > to add the oft-requested try/catch/finally syntax:
> >
> >   try {
> >     say "This happens first";
> >   }
> >   catch ($e) {
> >     say "Oops, a failure happened";
> >   }
> >   finally {
> >     say "This always happens, regardless of success or failure";
> >   }
> >
> > A try/catch/finally can be implemented basically the same way as if it
> > was written
> >
> >   {
> >     defer { "finally" code goes here }
> >
> >     try {} catch($e) ... here as normal
> >   }
>
> I've now written a (currently-draft) PR to implement specifically this
> bit of try/catch/finally syntax:
>
>   https://github.com/Perl/perl5/pull/19285
>
> Whether to allow try/finally without a catch block
>

I think allowing try/finally results in being used in the production at
experimental status.

If you haven't decided yet, it is good to forbid try/finally at first
implementation.

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