Re: Exceptions Vs Errors
| From: | Andrew Faulds | Date: | Sun, 02 Sep 2012 08:36:40 +0000 |
| Subject: | Re: Exceptions Vs Errors | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62660@lists.php.net to get a copy of this message | ||
On 02/09/12 02:39, Anthony Ferrara wrote:
Right now, I see the biggest problem with errors currently in PHP is that there's no easy way of discerning between error types to be able to handle them. Therefore it's easier to ignore the error than it is to handle it bluntly. For example, I may want to distinguish between failure modes of file_put_contents(). Right now, three types of errors can occur: File not writable (can't open it), Can't write to file (write failed), and Partial write only (but certain bytes were written). http://lxr.php.net/xref/PHP_5_4/ext/standard/file.c#661 Right now, there's no way short of parsing the error string to even attempt to distinguish between them (arguably the first two could be treated the same, but the third could lead to very dangerous situations). Which is non-trivial to say the least... Isn't one of the main points of using Exceptions that you can catch all exceptions (Exception) or subclasses (hypothetical IOException, etc.) or very specific ones (hypothetical IOFileOpenException)?
So, while I know there's some discontent about having the core raise exceptions, let me ask the question differently: Without moving to exceptions, how could the current error and error handling mechanisms be improved to make the scenario I posted above easier. To make handling errors just as easy as ignoring them (or preferably easier)...? I don't wish to derail this thread from the get-go, but what's your opposition to moving to exceptions?-- Andrew Faulds http://ajf.me/