Re: Re: Are exceptions allowed in php core?
| From: | Lester Caine | Date: | Sun, 02 Sep 2012 08:10:28 +0000 |
| Subject: | Re: Re: Are exceptions allowed in php core? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62657@lists.php.net to get a copy of this message | ||
Rasmus Lerdorf wrote:
On 09/01/2012 05:44 PM, Gustavo Lopes wrote:Finally I'm understanding what my problem is with a lot of this stuff. I kept looking at this and trying to understand exactly WHAT the flow through the code is. The 'magic' processing of generators is hiding away exactly where the source of a problem is. Showing me the code that is carrying out the processing, rewind, next etc ... at lease allows me to understand just what is throwing a problem when it happens - and handling the error! And yes an exception that gives a accurate error report is the only way of handling that without the visible code steps to error against? So we are back to the fundamental problem of how does one HANDLE that exception in an environment where they are currently only used in limited specific actions ... which may also be wrong! ... I prefer to code for and capture errors, so if the file does not exist I check for that and give the user a suitable warning. If I'm iterating a file and the read does not complete becuase of an OS read fault I like to capture that state and handle it. I can accept generators IF I can bail out with a suitable error when I need to, but exceptions are there simply because no one bothered to handle the real error? The work flow has been so screwed up that the only way out is to crash? -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.ukMore importantly, there is no other satisfactory solution (except a fatal error). foreach has no return value, so it has no other way to signal a failure. If we used a notice or a warning here what would happen is that code that used generators with an invalid state would, except for the notice, work as if it had been given an empty iterator. Put another way, it would fail with only a notice, and continue. That is a far more serious problem. In other circumstances where we emit warnings, we usually have a return value the caller can check for error conditions.This is the real question here. It actually isn't about Exceptions at all. It is whether trying to iterate a closed generator should be a fatal error that breaks script execution right then and there. Whether that is done as an exception or a fatal error isn't actually all that relevant since the end result will be the same for most people. If everyone is in agreement that this should be a fatal error (I don't personally get why it has to be fatal) then lets just make it a fatal error and when we come up with a decent proposal for turning recoverable fatals into exceptions language-wide we can revisit this. And this might even be in the same release, so...