Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87500 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11343 invoked from network); 2 Aug 2015 11:10:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2015 11:10:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=markus@malkusch.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=markus@malkusch.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain malkusch.de designates 31.47.225.241 as permitted sender) X-PHP-List-Original-Sender: markus@malkusch.de X-Host-Fingerprint: 31.47.225.241 malkusch.de Received: from [31.47.225.241] ([31.47.225.241:60835] helo=malkusch.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/00-09373-09AFDB55 for ; Sun, 02 Aug 2015 07:10:11 -0400 Received: from f052011062.adsl.alicedsl.de ([78.52.11.62] helo=[192.168.1.90]) by malkusch.de with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.84) (envelope-from ) id 1ZLr9Z-0005xN-G1; Sun, 02 Aug 2015 13:10:05 +0200 Message-ID: <55BDFA85.9050300@malkusch.de> Date: Sun, 02 Aug 2015 13:09:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Stephen Coakley , internals@lists.php.net References: <55BBD019.5030106@stephencoakley.com> <55BC201D.6010600@malkusch.de> <55BC9361.1080804@malkusch.de> <55BCA7EE.4030301@gmx.de> <55BCDB57.5060609@malkusch.de> <6F.20.56402.69CADB55@pb1.pair.com> In-Reply-To: <6F.20.56402.69CADB55@pb1.pair.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.0 X-Spam-Score-Int: -9 X-Spam-Level: - Subject: Re: [PHP-DEV] Re: Throwable::addSuppressed() From: markus@malkusch.de (Markus Malkusch) Stephen Coakley: > This is the behavior in both Java and C#. Python has a different > approach. Python has two properties that contain previous exceptions: > __context__, which holds implicitly chained exceptions, and __cause__, > which holds explicitly chained exceptions. This system makes a ton of > sense, and I think PHP exceptions should distinguish between the two as > well. > > (Relevant PEP: ) Also thank you for that reference. As far as I understand this differs in two aspects: 1) __context__ is a single exception opposed to having a list of suppressed exceptions. This probably needs some more discussion to decide the approach. Although I would prefer having a list of suppressed exceptions I could imaging that as well. A list of suppressed exceptions would make things like this possible: } catch (Exception $e1) { foreach ($resources as $resource) { try { $resource->close(); } catch (Exception $e2) { $e1->addSuppressed($e2); } } throw $e1; } And just in case if in some distant future one might propose something like Java's try-with-resource PHP can easily do so without any BC break. 2) Caught exceptions will be considered as context as well. I'd say PHP should not adopt that behaviour. First I'd like to understand the semantic of suppressed as "a not caught exception". In Pythons world it's called context, and therefore acceptable. But more than that this leads to things like this: try: raise Exception("exception 1") except Exception as e: raise Exception("exception 2") from e In this case exception 2 has exception 1 both as context and cause. I think we don't need that information as we explicitly know by catching the exception already the context. Markus Malkusch