Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77800 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70821 invoked from network); 7 Oct 2014 13:58:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Oct 2014 13:58:19 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:36707] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/D8-30869-971F3345 for ; Tue, 07 Oct 2014 09:58:19 -0400 Received: by mail-wi0-f173.google.com with SMTP id fb4so7939589wid.12 for ; Tue, 07 Oct 2014 06:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=uGwBiLJOtwwU5ubWAoP/ktuuHPU9zeNj7ebSJ51g1/s=; b=fyPRtOYlJcfsJElsBIxzYzFtOfBbTqVrD2h+7Md4OlcDRycQgLRXd2tbIlWNyesihO T6Ko/2BFP3EXGdiewnflrWiYIIZc/jbEs7wjFL4/tKXJHzXZTuZjDUPvFyscABYGZRZV lGztiXIdIiYiSw1Ls3tNdQTYN9V4qPXHlauoVlGv1dlKbnyuOH21UKqscpjfHVaHjHf9 Ig6zvHxrmyW7l+N2n/UXI8x9l5UbBs401C+CoIdM4zq7ONfPt/RAFCvisBtDaK5FmVvf Xk0qkKu+dSzD1MGoS849krxX59a9h8Q3HtRhcgR9I0bQANpc5xUlDDVzx9kMXLS099OC r6+w== X-Received: by 10.180.84.98 with SMTP id x2mr4746904wiy.18.1412690294289; Tue, 07 Oct 2014 06:58:14 -0700 (PDT) Received: from [192.168.0.177] ([62.189.198.114]) by mx.google.com with ESMTPSA id cz3sm20862207wjb.23.2014.10.07.06.58.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Oct 2014 06:58:13 -0700 (PDT) Message-ID: <5433F174.8060204@gmail.com> Date: Tue, 07 Oct 2014 14:58:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <9CFCFC24-A670-4DBC-8042-C073B62958A2@strojny.net> In-Reply-To: <9CFCFC24-A670-4DBC-8042-C073B62958A2@strojny.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Exceptions in the engine From: rowan.collins@gmail.com (Rowan Collins) 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). Regards, -- Rowan Collins [IMSoP]