Re: [RFC Discussion] Catching multiple exception types
| From: | Marco Pivetta | Date: | Wed, 09 Mar 2016 13:08:11 +0000 |
| Subject: | Re: [RFC Discussion] Catching multiple exception types | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-91585@lists.php.net to get a copy of this message | ||
On 9 March 2016 at 14:03, Pierrick Charron <pierrick@adoy.net> wrote:
> Hi Derick
>
> I agree that most of the time the best solution is to implement a clean
> exception hierarchy but as stated in the RFC :
>
> "A solution to fix this problem on the user level would be to implement a
> common interface for ExceptionType1 and ExceptionType2 and catch it.
> However, this is only possible when you control the exception hierarchy in
> your own code, but not possible when you don't control the code."
>
I understand the use-case, but I don't see it as a widespread scenario. In
most cases, I've been doing something like following:
public function stuff()
{
try {
$this->willFail();
} catch (FirstException $e) {
$this->handleFailure($e);
} catch (SecondException $e) {
$this->handleFailure($e);
} catch (ThirdException $e) {
$this->handleFailure($e);
}
}
Even then, this is a rare eventuality, and as pointed out above, usually
fixed when wrapping exceptions correctly, if you have control over the
exception types).
Seems way below the 80/20 use-case to me, and introduces syntax changes as
well.
Cheers,
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/