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

Re: RFC 0004 - defer {} syntax

Thread Previous | Thread Next
From:
David Nicol
Date:
July 2, 2021 16:57
Subject:
Re: RFC 0004 - defer {} syntax
Message ID:
CAFwScO_LLUEo1nHL6T0NAd3H=P-OfZ4YDpCD47aGDP3PpY4PHw@mail.gmail.com
the multiple exceptions behavior looks like a bug to be repaired, not a
feature to be accommodated.

IMO The first exception thrown from deferred code should prevent later
defer blocks in that scope from happening, just as if they were later in
the code text, instead of getting rearranged there through defer sugar.

sub foo { say "Hi"; die "two"; die "one" }  # should this not be equivalent?

On Fri, Jul 2, 2021 at 4:45 AM Nicholas Clark <nick@ccl4.org> wrote:

>
> ## Error handling differs between `eval` and not.
>
> I think that this would be the first time in perl that the behaviour
> between
> `eval` and not eval differs. In that without eval:
>
> $ ./perl -Ilib -E 'use feature "defer"; sub foo { defer { die "One"; }
> defer { die "Two" } say "Hi"}; foo(); say "Bye"'
> defer is experimental at -e line 1.
> defer is experimental at -e line 1.
> Hi
> Two at -e line 1.
> One at -e line 1.
>
>
> We get both exceptions to STDERR and then the process exits:
>

-- 
"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash

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