Re: [VOTE] Allowing use of exceptions in the engine

From: Date: Mon, 09 Dec 2013 18:10:17 +0000
Subject: Re: [VOTE] Allowing use of exceptions in the engine
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-70563@lists.php.net to get a copy of this message
On Mon, Dec 9, 2013 at 11:41 AM, Nikita Popov <nikita.ppv@gmail.com> wrote: > On Mon, Dec 9, 2013 at 5:22 PM, Zeev Suraski <zeev@zend.com> wrote: >> >> For me it is an argument. Instead of being able to handle these errors in >> the same way they handle all other errors, now they have to learn new >> syntax and concepts. I see no reason to change the status quo, which >> allows those who want exceptions to easily convert errors to thrown >> exceptions, into a state where those who don't want to use exceptions are >> forced to use them. Again, it's entirely fair that we disagree... > > > You can't convert fatal errors to exceptions using an error handler. That's > why I'm targeting fatal errors here and not all errors in general. While I'm > not a big fan of PHP's error system in general, it's easy enough to turn > warnings or notices into exceptions via error handlers. But for fatal errors > that's just not possible. > > To achieve what I want it would be enough to turn fatal errors into > recoverable fatal errors, that would already allow the error handler > approach. But that's a lot harder to do (and imho less usable) than directly > using exceptions. Keeping the engine stable after an exceptions is > relatively simple, the same can't be said about recoverable fatals. > > Regarding the "forcing OO concepts": As Philip pointed out, unless you > already make use of try/catch a fatal error and an uncaught exception are > about the same to the end user - actually, an uncaught exception is just a > special fatal error. I could totally understand your concerns - if this > discussion weren't about fatal errors. E.g. changing a warning to an > exception would cause lots of issues. The @ operator would stop working and > people would be forced to use try/catch. But for fatals @ never worked in > the first place. You can't handle them right now. Changing them to > exceptions adds the ability to handle them via try/catch, but of course you > don't need to do them. You can let them bubble (and in most cases that's > what you should do) and let them effectively act the same way as a fatal > error currently does, just with a bit of a different message ;) > > Thanks, > Nikita Right. Put simply: 1. Users who previously did not care about exceptions will continue to not care about exceptions, and do not have to do anything any differently. 2. Users who want to handle fatal errors somehow (because you currently cannot) can use this to catch them. Nobody needs to work with exceptions if they dont want to, that fatal error just shows up as a uncaught backtrace and fatals errors just like it used to. Seems like a win win.

« previous php.internals (#70563) next »