Re: Re: "TryX" idom for Enumerations
| From: | Rowan Tommins | Date: | Fri, 15 Jan 2021 21:43:12 +0000 |
| Subject: | Re: Re: "TryX" idom for Enumerations | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112908@lists.php.net to get a copy of this message | ||
On 10/01/2021 22:40, Mark Randall wrote:
There is an alternative, of sorts. Something I tried investigating when I first started looking into PHP-SRC, but lack the skill and knowledge to implement myself. A shorthand try / catch of something like the form: <tryname>(<expr, ExceptionType => ResultExpr, ...)Funnily enough, I just wrote an aide that a language could provide this in a discussion of indicating errors via throw vs return. [1] My contention being that exceptions make it easier to express "do these steps in order and abort the whole sequence on the first error", but harder to express "combine these results, but if this one errors substitute this value", because an exception always implies a jump in control flow. Larry makes a good point that the capture of a stack trace for exceptions makes them unnecessarily expensive in cases where you're immediately handling them, though. I don't know if there's a way around that, without re-designing exceptions completely. [1] https://softwareengineering.stackexchange.com/a/421004/96713 Regards, -- Rowan Tommins [IMSoP]