Re: Re: Are exceptions allowed in php core?
| From: | Gustavo Lopes | Date: | Sun, 02 Sep 2012 00:57:12 +0000 |
| Subject: | Re: Re: Are exceptions allowed in php core? | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62644@lists.php.net to get a copy of this message | ||
On Sun, 02 Sep 2012 02:37:50 +0200, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
The position that we should not use *more* exceptions in the core is of course legitimate. But let's not temper with the factual record to make an argument for it. This discussion should have started with an accurate description of the current state.* If users do not expect exceptions in the core, they are mistaken. There are indeed exceptions in the core. See ZEND_FE_RESET and zend_interfaces.c. Of course, no evidence has been provided one way or another.This is not right either, but that was done in 2005. We're now in 2012 and trying to make PHP a bit more orderly.
I'm not sure what you're saying that is not your argument. What you cite is an argument of mine, not yours. After that, you're basically saying the same thing as Derick -- that because you're not instantiating a class directly, you don't know that you're working with an object API that includes exceptions. I don't really have a argument for that except that users should know that generators return a sort of iterators. But in any case, the argument that you have to wrap foreach() in try-catch blocks is weak. That's like saying that in Java you have to try-catch IllegalStateExceptions all the time. The truth is, correct code will never throw these exceptions. As I explained in the reply to Rasmus' e-mail, a fatal error would also be somewhat appropriate (though inconsistent with the other Zend interfaces), but definitely a warning is not. -- Gustavo Lopes* In fact, if there is a unifying theme in the usage of exceptions in PHP, is that exceptions are used when OOP interfaces are involved (see Zend interfaces, SPL, DateTime and PDO -- though optional there). The core vs. non-core argument only looks attractive because there are few built-in classes in the core.That's not my argument. My argument is when you instantiate some class explicitly and work with it, you know you're dealing with certain API that may include exceptions. When you're using foreach(), you don't expect to wrap each foreach() into a try-catch block. But that's what is happening here.