Kevin,

On Wed, Jun 17, 2015 at 4:41 PM, Kevin Bradwick <kevinbradw...@gmail.com> wrote:
> Hello!
>
> This is my first post to the internals list so please forgive me if I have
> not followed the rules precisely!
>
> I've had an idea to improve how developers use exceptions within PHP. I'd
> like to add an RFC but as per the instructions on the site
> <https://wiki.php.net/rfc/howto>, I am sending this email first gauge
> reaction as an initial idea.
>
> The idea is to change the base Exception
> <http://php.net/manual/en/class.exception.php> class to be abstract. The
> reason for this is to encourage developers to extend it to create meaning
> exceptions or use the standard SPL exceptions. The documentation states
> that it's the base class for all exceptions, which kind of encourages my
> thought process.
>
> Too many times have I seen developers throwing Exceptions when what they
> really needed was something that gave it context like
> InvalidArgumentException or RuntimeException. Yes, I agree this is
> something to tackle at code review (and I do) but I feel PHP doesn't help
> the situation by making it an instantiatable class. I struggle to think of
> a valid reason where it makes sense to throw the root Exception class.
> Catching the root Exception class is a different matter and there are
> perfectly valid cases for doing it.
>
> So, what does everyone think? Is it worth me pursing the RFC with full
> details of the idea or am I on my own with this one?
>
> Many thanks!
> Kevin

Changing the existing Exception class to be abstract would break a
metric ton of code. Simply on that metric alone it would be a hard
sell. I think you'd need an exceptionally strong justification for it,
beyond "using typed exceptions is better".

Instead, I think we should solve the problem with education. Perhaps
the documentation can better detail out why devs shouldn't directly
throw exception but instead use typed exceptions...?

My $0.02 at least...

Anthony

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to