Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69850 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51408 invoked from network); 24 Oct 2013 19:27:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Oct 2013 19:27:46 -0000 X-Host-Fingerprint: 80.4.21.210 cpc22-asfd3-2-0-cust209.1-2.cable.virginm.net Received: from [80.4.21.210] ([80.4.21.210:7137] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/6F-10840-2B479625 for ; Thu, 24 Oct 2013 15:27:46 -0400 To: internals@lists.php.net,Nikita Popov Message-ID: <526974AE.1050601@php.net> Date: Thu, 24 Oct 2013 20:27:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 80.4.21.210 Subject: Re: [RFC] Exceptions in the engine From: krakjoe@php.net (Joe Watkins) On 10/24/2013 06:41 PM, Nikita Popov wrote: > Hi internals! > > I'd like to propose an RFC, which allows the use of exceptions within the > engine and also allows changing existing fatal errors to exceptions: > > https://wiki.php.net/rfc/engine_exceptions > > This topic has been cropping up in the discussions for several of the > recent RFCs and I think the time has come to consider moving away from > fatal errors. > > Thoughts? > > Thanks, > Nikita > Delicious, obviously ... I will add that; if we are going to push forward with using exceptions properly, then there's internal code throwing base Exceptions objects and that needs to be fixed, catch(Exception $ex) will have _even less meaning_ than it does today if we are to throw exceptions in place of fatal errors. I have to ask the question; why stop at half way ?? A warning does absolutely nothing for the programmer, or their code, all it does is warn the client, who isn't very likely to even be in contact with the programmer, even less likely has access to their code. Take the following code: $handle = fopen("/path/to/file", "w+"); if ($handle) { } If there is no $handle, I have no idea why, god only knows what the logic looks like to detect why the failure occurred, and it doesn't have to be fopen, can be almost anything that doesn't throw exceptions. So, even though, some previously called function or method almost certainly has some information that is useful, I have to make more sys or library calls to determine the nature of the error and the code path to take. try { $handle = fopen ("/path/to/file", "w+"); } catch (FileNotFoundException $fnf) { } catch (PermissionException $pex) { } catch (DiskFullException $dfe) { } [Note: the names of the exceptions and functions used _do not matter_, consider the pattern only] This solution has existed for years, why do we shy away from it so much ?? I've never heard a really good argument for the existence of warnings or notices at all. This is all said with the knowledge that some errors are truly fatal, there is no point to, or chance of, throwing an exception. +1 on the whole idea, however far we are able to take it ... the further the better in my opinion ... Cheers Joe