Re: Exceptions Vs Errors
| From: | Gustavo Lopes | Date: | Sun, 02 Sep 2012 08:55:36 +0000 |
| Subject: | Re: Exceptions Vs Errors | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62662@lists.php.net to get a copy of this message | ||
On Sun, 02 Sep 2012 03:39:15 +0200, Anthony Ferrara <ircmaxell@gmail.com> wrote:
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.I don't think your specific scenario needs to be improved. file_put_contents() is a high level function with coarse error reporting. If you need to distinguish the problems, you can open the files separately, and use stream_copy_to_stream(). But in any case, for the general problem you're raising -- that false does not give enough information for handling the error, the solution is well-established: you have some way of getting the error code. This can be done either through a dedicated function (like curl_errno, mysqli_errno) or through extra parameters, like it's done in stream_socket_client(). And yes, it's unfortunate we don't have any sort of common interface or even consistency in this area.
To make handling errors just as easy as ignoring them (or preferably easier)...?I don't think that's feasible, except maybe by using checked exceptions (which most people hate, with good reason). Writing bad exception-based code and bad error-code-based code is always easy. See the tables here: http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/352949.aspx -- Gustavo Lopes