FAQ

On 9 March 2016 at 14:03, Pierrick Charron 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/

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 11 of 19 | next ›
Discussion Overview
groupphp-internals @
categoriesphp
postedMar 8, '16 at 9:42p
activeMar 19, '16 at 9:09p
posts19
users10
websitephp.net

People

Translate

site design / logo © 2019 Grokbase