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

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

Thread Previous | Thread Next
Paul "LeoNerd" Evans
December 16, 2021 22:23
Re: Pre-RFC: try/catch/finally and generic finally blocks
Message ID:
On Tue, 19 Oct 2021 19:25:04 +0100
"Paul \"LeoNerd\" Evans" <> 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:

It doesn't yet address such questions as `finally` on bare blocks or
other situations.

It also doesn't address the question of how to deparse compiled code
using this syntax, as it is currently implemented by the same optree as
a `defer` block would use, and is thus indistinguishable, in much the
same way that "A and B" and "B if A" would deparse the same way.

Paul "LeoNerd" Evans      |  |

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