Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77814 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2152 invoked from network); 7 Oct 2014 17:52:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Oct 2014 17:52:43 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.174 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.174 mail-ob0-f174.google.com Received: from [209.85.214.174] ([209.85.214.174:46852] helo=mail-ob0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/DE-30869-66824345 for ; Tue, 07 Oct 2014 13:52:40 -0400 Received: by mail-ob0-f174.google.com with SMTP id wp18so6041863obc.19 for ; Tue, 07 Oct 2014 10:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=WEeGo+ADCbq/VUbdtFkVhqsK1XQRefrAY6mi3BwSbZs=; b=Jak5XTy/6TVLuC4YdtrjOiKHJ5ETPqC1Xq5MnPjoMynjtwGzO885/ePP82v75diCWL AR1QMKL4w+qluD5uX4L9mNrOhr4EPive+F+IrQjs+r0UHV62M+xhsD7gvm+zgMJLHlWQ 4w2IAoC+sjKtH4+qL9+dJgxKWe/C2N/GdquRzR6hGa6RZ/EqSZOHPMCiXInR4RpMxq4B ucuFMcL+Klv9rHT6P+9YffZG2quIq86p2/3fYdmSWuNlCyDJ635+EWMgS+306Bdn6GJe F9vMRrw81l9VpODR+wcVrfcu8NMFk5wGLpPFEGUgjzQnT+axSeeS4saAXJs08PrFlBPu 7NFg== MIME-Version: 1.0 X-Received: by 10.60.56.39 with SMTP id x7mr2902000oep.62.1412704355861; Tue, 07 Oct 2014 10:52:35 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.76.75.37 with HTTP; Tue, 7 Oct 2014 10:52:35 -0700 (PDT) In-Reply-To: <5433F174.8060204@gmail.com> References: <9CFCFC24-A670-4DBC-8042-C073B62958A2@strojny.net> <5433F174.8060204@gmail.com> Date: Tue, 7 Oct 2014 11:52:35 -0600 X-Google-Sender-Auth: 11F8iMsfyAUC64ytVE0Nbz2mZFo Message-ID: To: Rowan Collins Cc: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Exceptions in the engine From: levim@php.net (Levi Morrison) On Tue, Oct 7, 2014 at 7:58 AM, Rowan Collins wrote: > Lars Strojny wrote (on 06/10/2014): > >> Hi Nikita, >> >> On 06 Oct 2014, at 23:53, Nikita Popov wrote: >> [...] >>> >>> As such I'm re-proposing this RFC for inclusion in PHP 7: >>> >>> https://wiki.php.net/rfc/engine_exceptions_for_php7 >>> >>> The RFC text is essentially the same as previously, with the primary >>> difference being that parse errors are now converted to exceptions as >>> well. >>> This was previously not possible due to limitations in the compiler >>> design. >> >> I very much like the idea of making fatal errors exceptions, so: thumbs >> up! Is there a way to introduce different exception classes for different >> errors. E.g. >> >> - UndefinedMethodException for stdClass::method() >> - NullPointerException for null::method() >> - UndefinedFunctionException for invalid_function() >> - etc. >> >> They could all extend EngineException to have a common base class but I am >> sure we could find good abstractions for an exception inheritance tree. >> >> What do you think? > > > It was suggested in the previous discussion that this could be added later, > but IMHO, it's a must. Part of the power of exceptions is that you can > *selectively* catch them *when you know you can deal with the result*. > > Emitting a single EngineException will just encourage a kind of "pokemon > exception handling", because the only way to use it is in a generic > "something went wrong" handler. The semantics of that handler might be a bit > tidier than one for E_RECOVERABLE_ERROR, but there's not a lot of extra > power available. > > As an example where a specific exception would be useful, but a generic one > would not, consider a fluent interface which sometimes bugs out and returns > NULL. If wrapped in a NullPointerException these expected error conditions > could be caught at runtime, while any other errors would continue to have > their normal behaviour (such as triggering a higher-scoped catch-all/default > exception handler). I would contend that catching a NullPointerException is not any more recoverable than most other EngineExceptions. I would also argue that you should never, in any language, catch a NPE. The only time you should catch an NPE is if you are catching all exceptions, such as in a FastCGI daemon that will cleanly shutdown afterwards.