Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77819 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13002 invoked from network); 7 Oct 2014 19:47:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Oct 2014 19:47:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:56380] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/B0-30869-C5344345 for ; Tue, 07 Oct 2014 15:47:42 -0400 Received: by mail-wi0-f180.google.com with SMTP id em10so9079777wid.1 for ; Tue, 07 Oct 2014 12:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=W1EnF1XALLVV/bunFuDKl85UKU7MNvn6TVl5EqXrlVs=; b=NYErkd0TKvNrFwQGAESGh+EDRBj9zlt6bEoK7ntrjdnn/KPJRd4FiC3UIq5Cqui7DE YlsjgU7AM1QkuCfuCcmrgiAyEAUg3+cMomETQsUc5MHPtk1S+uLzqNqc02y21cR6eebd HBQmXu+XtuX9g6hkTD71jjcPTZPXjiF3LVHzXIy6rgEUb5vVNnPukY5qt4yplZu20m8+ qdq84zkbEBTdFxODIA5MO6nX69GLRqIXx25f4+oj47B6JMSq+SLRh/Gtl6S2IJCklNCU P9G2TEDQ9ZyGR/Qq3UG6j6mXH3O8kJW0r/cUQL3RunARJO6eijaOJVDhKUGO2dr659g+ 0lwg== X-Received: by 10.180.182.166 with SMTP id ef6mr13448194wic.10.1412711257363; Tue, 07 Oct 2014 12:47:37 -0700 (PDT) Received: from [192.168.0.3] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id s1sm15959575wiw.6.2014.10.07.12.47.36 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Oct 2014 12:47:36 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: <9CFCFC24-A670-4DBC-8042-C073B62958A2@strojny.net> <5433F174.8060204@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Tue, 07 Oct 2014 20:46:29 +0100 To: internals Message-ID: Subject: Re: [PHP-DEV] [RFC] Exceptions in the engine From: rowan.collins@gmail.com (Rowan Collins) On 7 October 2014 18:52:35 GMT+01:00, Levi Morrison wrote: >On Tue, Oct 7, 2014 at 7:58 AM, Rowan Collins >wrote: >> 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. In the scenario I just listed, the catch is effectively emulating an isset()/is_object() check before each chained operation. Seems perfectly reasonable to me. (If I'm not much mistaken, CoffeeScript has an operator for this precise case.) > 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. If you're not allowed to catch it, why make it an exception? Benefits such as unwinding finally blocks and destructors, and collecting backtraces, are secondary effects, not really fundamental to exceptions. Perhaps "NullPointerException" is not a good name, as it has rather different implications than in other languages. In PHP, using the -> operator on a non-object isn't much different from calling a function with incorrect types. It shouldn't happen if your code is properly unit-tested, but it doesn't necessarily mean a catastrophic failure has occurred. Regards, -- Rowan Collins [IMSoP]