develooper Front page | perl.perl5.porters | Postings from July 2020

Re: try/catch and CLEANUP/FINALLY/&c.

Thread Previous | Thread Next
From:
=?UTF-8?Q?Branislav_Zahradn=C3=ADk?=
Date:
July 17, 2020 05:11
Subject:
Re: try/catch and CLEANUP/FINALLY/&c.
Message ID:
CAB=rbOm23s=+rOTTCLSHw+dbgFU7P4HqT5WVpjhjNK2Jn-jC_A@mail.gmail.com
On Thu, 16 Jul 2020 at 14:48, Felipe Gasper <felipe@felipegasper.com> wrote:

> My understanding is that CLEANUP (“FINALLY”?) blocks essentially build
> into the language the functionality of modules like Scope::Guard, but
> without the Perl-level guard object.
>
> The well-known try/catch/finally pattern would then look thus:
>
> {
>         CLEANUP { print 3 }
>
>         try {
>                 print 1;
>                 die 'oh no';
>         }
>         catch {
>                 print 2;
>         }
> }
>
>
Let's extrapolate, imagine both CLEANUP and CATCH as lexical constructs ...

{
        CLEANUP { print 3 }
        CATCH { print 2 }

        print 1;
        die 'oh no';
}

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