Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87489 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61550 invoked from network); 2 Aug 2015 05:37:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2015 05:37:34 -0000 X-Host-Fingerprint: 68.118.157.39 68-118-157-39.dhcp.mdsn.wi.charter.com Received: from [68.118.157.39] ([68.118.157.39:28139] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/20-56402-69CADB55 for ; Sun, 02 Aug 2015 01:37:31 -0400 Message-ID: <6F.20.56402.69CADB55@pb1.pair.com> To: internals@lists.php.net Date: Sun, 02 Aug 2015 00:37:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 References: <55BBD019.5030106@stephencoakley.com> <55BC201D.6010600@malkusch.de> <55BC9361.1080804@malkusch.de> <55BCA7EE.4030301@gmx.de> <55BCDB57.5060609@malkusch.de> In-Reply-To: <55BCDB57.5060609@malkusch.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 68.118.157.39 Subject: Re: [PHP-DEV] Re: Throwable::addSuppressed() From: me@stephencoakley.com (Stephen Coakley) On 08/01/2015 09:44 AM, Markus Malkusch wrote: > Christoph Becker: >> Markus Malkusch wrote: >>> >>> I'd like to revise that. I'd just learned that finally does indeed fit >>> here, as it would automatically glue exceptions: > > [..] > >> Note that there's an open bug report () >> regarding this issue. > > Thank you for pointing to that bug. So I understand the authors of that > bug are surprised that finally does magically attach exceptions. I did > actually also not expect that, as it is not documented nor do I have > that experience from other languages (did only check with Java). > > So I can assume that magic finally glue behaviour is not considered > stable, which then again gives Throwable::addSupressed() IMO a > justification. > > Markus Malkusch > So what should be the desired behavior, in regard to bug #68270? One possible behavior would be to, if an exception is thrown inside a finally block, to attach the uncaught exception from the try block via the addSupressed() method. The last exception is thrown, and the exception in the try block is still not lost. Such an alternative could be bundled with the RFC. The alternative s to just drop the exception, never to be seen again. 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: ) Currently, in the try/finally situation described, $previous is used to hold the missing exception. $previous should only hold explicitly passed exceptions, as described in the docs. addSupressed() could be defined as for implicit chained exceptions. The method could be paired with a Throwable::getSupressed() to retrieve the implicitly added exception. So in a case like this: try { try { throw new Exception("Exception 1"); } finally { throw new Exception("Exception 2"); } } catch (Throwable $e) { var_dump($e->getSupressed()); } we would have $e be exception 2, and $e->getSupressed() return exception 1. The more I think about it, the better the idea sounds. Good thought, Markus! -- Stephen Coakley