Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87541 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38032 invoked from network); 2 Aug 2015 21:35:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2015 21:35:31 -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:5516] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/5C-55344-22D8EB55 for ; Sun, 02 Aug 2015 17:35:30 -0400 Message-ID: To: internals@lists.php.net Date: Sun, 02 Aug 2015 16:35:25 -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> <6F.20.56402.69CADB55@pb1.pair.com> <55BDD9E0.6090801@malkusch.de> In-Reply-To: <55BDD9E0.6090801@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/02/2015 03:50 AM, Markus Malkusch wrote: > Stephen Coakley: > >> 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. > > I also like that idea very much that the try-exception is not lost in > this case. So I would agree defining this behaviour can be part of the > RFC as well. Also the current behaviour is nowhere documented so > changing it can be considered as backward compatible (plus it would > close bug #68270). > >> 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. > > Ack. But the original idea was that Throwable::getSupressed() will > return a *list* of exceptions. You probably didn't change that > intentionally. The try-finally scenario involves only one supressed > exception. I'd like to see a possibility to add more supressed > exceptions, as described in the initial mail for e.g. a use case where > just more resources need to be closed. > > Now that try-finally is part of the scope as well, I'd like to add the > case that a supressed exception might be thrown from a catch block as well: > > try { > throw new Exception("Exception 1"); > > } catch (Exception $e) { > throw new Exception("Exception 2", 0, $e); > > } finally { > throw new Exception("Exception 3"); > } > > So in this case the resulting exception would be exception 3, which has > exception 2 as a supressed exception. Exception 1 is as already defined > the previous exception of exception 2. > >> The more I think about it, the better the idea sounds. Good thought, > > Good to hear that the idea finds acceptance. Also I like the evolving of > it. I guess drafting a RFC might be an option then. I will let this idea > brew a bit and then start with that, assuming doing so is fine. > > Markus Malkusch > Ah, yes. I didn't realize that was the intention, but Throwable::getSupressed() could return an array. -- Stephen Coakley