Re: Making "match" catch exceptions
| From: | Olle Härstedt | Date: | Fri, 26 Mar 2021 22:58:09 +0000 |
| Subject: | Re: Making "match" catch exceptions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-113807@lists.php.net to get a copy of this message | ||
2021-03-26 23:00 GMT+01:00, Rowan Tommins <rowan.collins@gmail.com>:
> On 26/03/2021 16:45, Olle Härstedt wrote:
>> That made me think of a recent
>> extension to OCaml which makes it possible to catch exceptions in a
>> match-expressions (here's one blog post about it:
>>
>> https://blog.janestreet.com/pattern-matching-and-exception-handling-unite/).
>
>
> That's an interesting idea. I wonder if it would provide a way to
> implement the "data-flow" or "expression context" exception handling I
> was discussing on a different thread recently.
>
> Looking at my previous example:
>
> try {
> $foo = doSomething() + $bar;
> }
> catch ( SomeException $e ) {
> $foo = $bar;
> }
>
> Would become something like this:
>
> $foo = match($temp = doSomething()) {
> exception SomeException => 0,
> default => $temp
> } + $bar;
You can't catch the value of $temp in the match-case?
$foo = $bar + match (doSomething()) {
$temp => $temp,
exception SomeException => 0
};
Olle