Re: [RFC] Exceptions in the engine
| From: | Rowan Collins | Date: | Wed, 25 Feb 2015 13:19:18 +0000 |
| Subject: | Re: [RFC] Exceptions in the engine | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83784@lists.php.net to get a copy of this message | ||
Tony Marston wrote on 21/02/2015 10:08:
""Nikita Nefedov"" wrote in message news:op.xuco5eutc9evq2@nikita-pc...But what about this code, which could well already exist: try {On Fri, 20 Feb 2015 12:39:33 +0300, Tony Marston <TonyMarston@hotmail.com> wrote:I disagree. The following function calls would not throw exceptions fopen(...); fwrite(...); fclose(...); while the following code would: try {I disagree. Exceptions were originally invented to solve the semipredicate problem which only exists with procedural functions, not object methods. Many OO purists would like exceptions to be thrown everywhere, but this would present a huge BC break. If it were possible get these functions to throw an exception ONLY when they are included in a try ... catch block then this would not break BC at all.Tony, first of all - this still breaks BC, because exception is being thrown in a place where it used not to be...fopen(...); fwrite(...); fclose(...);} catch (....) {.... }
$fh = fopen(...);
$this->processLotsOfDataAndMaybeThrowAnException($fh);
fclose($fh);
} catch (....) {
....} If fopen() starts throwing exceptions here, that's as much a BC break as it throwing them everywhere. If it doesn't, the rules for when it should throw become even more complicated, and useful in even fewer cases. Regards, -- Rowan Collins [IMSoP]