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

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

Thread Previous | Thread Next
From:
Felipe Gasper
Date:
July 17, 2020 14:18
Subject:
Re: try/catch and CLEANUP/FINALLY/&c.
Message ID:
2FB23416-C3A4-412C-939F-3FD15C362C94@felipegasper.com

> On Jul 17, 2020, at 1:31 AM, Felipe Gasper <felipe@felipegasper.com> wrote:
> 
> Maybe try/catch/finally is actually less useful in general than a CLEANUP that fires at the end of the block that contains the try/catch. I can’t say what’s most useful to a typical Perl developer--much less a “potential” Perl developer.

Postscript to this: In my JS work I typically do things like:

=====
show_notification('Frobnicating …');

try {
    attempt_frobnication();
    report_success();
}
catch (e) {
    report_failed_frobnication(e);
}
finally {
    hide_notification();
}
=====

… in which context I definitely want the “cleanup” logic to fire immediately after the try/catch.

Without a “standard” finally block I could do it with a scope-guard by undef()ing the reference after the catch block. With the proposed CLEANUP {} I’d need an extra code block around the try/catch.

-FG
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