* Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> [2021-12-16 22:22:56 +0000]: > 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 > > } Pardon me if I still have not gotten this clear in the space between my ears, but why not call it "finally"? "defer" begs the question, "defer until when?"; "finally" asks and answers this quite succinctly. Cheers, Brett > > 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/ -- -- oodler@cpan.org oodler577@sdf-eu.org SDF-EU Public Access UNIX System - http://sdfeu.org irc.perl.org #openmp #pdl #nativeThread Previous | Thread Next