develooper Front page | perl.perl5.porters | Postings from June 2022

Re: $@ alternative WAS Re: Core exception types [was: Re: Pre-RFC: Improve “wide character” warnings]

Thread Previous | Thread Next
From:
Felipe Gasper
Date:
June 8, 2022 19:46
Subject:
Re: $@ alternative WAS Re: Core exception types [was: Re: Pre-RFC: Improve “wide character” warnings]
Message ID:
61D42928-7365-494E-B8FF-F134751E9F0F@felipegasper.com

> On Jun 8, 2022, at 13:38, Dan Book <grinnz@gmail.com> wrote:
>  
> As was shown in the example, you don't actually use the proposed variable yourself in try/catch as it sets up a lexical variable for the scope of catch.

That would certainly encourage adoption of try/catch.

> As an alternative: what if, under `use feature 'errorobject'`, $@ were the object, but without the feature it’d be the string? So the feature would only change how eval populates $@.
> 
> This is not possible, because it is not populated lexically. 

I don’t think that matters:

-----
{
    use feature 'errorobject';

    eval { 9 / 0 };
}

say blessed $@; # prints something

{
    no feature 'errorobject';

    eval { 9 / 0};
}

say blessed $@; # prints nothing
-----

Whenever $@ is populated, the relevant logic would check to see if the active feature set dictates putting the object or the string into $@.

-F

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