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;
Hm, that's not the most elegant; even if we could avoid the $temp
assignment, the "default to myself" seems superfluous for this use case.
I can definitely see the feature having its use cases, though, was just
kicking this around as a thought experiment.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php