Re: [RFC] Exceptions in the engine
| From: | Rowan Collins | Date: | Tue, 07 Oct 2014 13:58:12 +0000 |
| Subject: | Re: [RFC] Exceptions in the engine | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77800@lists.php.net to get a copy of this message | ||
Lars Strojny wrote (on 06/10/2014):
Hi Nikita, On 06 Oct 2014, at 23:53, Nikita Popov <nikita.ppv@gmail.com> wrote: [...]It was suggested in the previous discussion that this could be added later, but IMHO, it's a must. Part of the power of exceptions is that you can *selectively* catch them *when you know you can deal with the result*. Emitting a single EngineException will just encourage a kind of "pokemon exception handling", because the only way to use it is in a generic "something went wrong" handler. The semantics of that handler might be a bit tidier than one for E_RECOVERABLE_ERROR, but there's not a lot of extra power available. As an example where a specific exception would be useful, but a generic one would not, consider a fluent interface which sometimes bugs out and returns NULL. If wrapped in a NullPointerException these expected error conditions could be caught at runtime, while any other errors would continue to have their normal behaviour (such as triggering a higher-scoped catch-all/default exception handler). Regards, -- Rowan Collins [IMSoP]As such I'm re-proposing this RFC for inclusion in PHP 7:I very much like the idea of making fatal errors exceptions, so: thumbs up! Is there a way to introduce different exception classes for different errors. E.g. - UndefinedMethodException for stdClass::method() - NullPointerException for null::method() - UndefinedFunctionException for invalid_function() - etc. They could all extend EngineException to have a common base class but I am sure we could find good abstractions for an exception inheritance tree. What do you think?https://wiki.php.net/rfc/engine_exceptions_for_php7The RFC text is essentially the same as previously, with the primary difference being that parse errors are now converted to exceptions as well. This was previously not possible due to limitations in the compiler design.