facebook / facebook/hhvm

[ Feature Request ] try {} catch {} multiple-catch

Open
#8,717 1 comment 0 reactions 0 assignees View on GitHub
feature request
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

**Is your feature request related to a problem? Please describe.**
One of the things I "miss" from the PHP days is support for [multiple-catch](https://wiki.php.net/rfc/multiple-catch). This was a nice to have and really helps when refactoring exceptions, since you need to catch OldException and NewException and treat them the same until OldException is no longer being thrown.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

```PHP
getMessage(), $e->getCode(), $e);
}
} catch (\OutOfBoundsException $e) {
// code that runs when either of these OOB or OOR is caught.
}
```

**Additional context**
Add any other context or screenshots about the feature request here.

HHVM did not support this PHP 7.1 feature in hhvm 3.30, so there may very well be engine limitations for why this could not be implemented.

Having this in Hack before the introduction of (internal) union types in hhvm [4.14.0](https://hhvm.com/blog/2019/07/15/hhvm-4.14.0.html) would have been required the inference to infer the greatest common divisor of these types `\Exception` or unresolved of OOR and OOB.
However, Hack now understands unions in inference and creating variables that hold intersections is not something we couldn't already do with `$e = \random_int(0, 1) ? new A() : new B()`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.