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 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 leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/Thread Previous | Thread Next