Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87358 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51232 invoked from network); 28 Jul 2015 22:30:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2015 22:30:08 -0000 Received: from [127.0.0.1] ([127.0.0.1:2091]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 06/F4-22108-F6208B55 for ; Tue, 28 Jul 2015 18:30:07 -0400 X-Host-Fingerprint: 85.179.132.148 x55b38494.dyn.telefonica.de Received: from [85.179.132.148] ([85.179.132.148:26713] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/64-22108-E69F7B55 for ; Tue, 28 Jul 2015 17:51:43 -0400 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Date: Tue, 28 Jul 2015 23:51:39 +0200 User-Agent: KNode/4.14.8 Content-Transfer-Encoding: 8Bit Lines: 49 MIME-Version: 1.0 X-Posted-By: 85.179.132.148 Subject: Throwable::addSuppressed() From: markus@malkusch.de (Markus Malkusch) Hi PHP So I read that there's this Throwable interface coming. Great! How about extending it with one further method: void Throwable::addSuppressed(Throwable exception) Semantic is the same as Java's Throwable.addSuppressed()ยน. Why? Well consider a code fragment which wants to close a resource during an exception: } catch (Exception $e1) { try { $resource->close(); throw $e1; } catch (ResourceException $e2) { // The information about $e2 is lost. throw $e1; } } Currently PHP has no method to propagate both $e1 and $e2. With Throwable::addSuppressed() $e2 could be added as a suppressed exception to $e1: } catch (Exception $e1) { try { $resource->close(); } catch (ResourceException $e2) { e1->addSuppressed($e2); } throw $e1; } To make this information useful (for e.g. a logger) there's one further method needed: Throwable[] Throwable::getSuppressed() So PHP, what do you think, might a RFC find acceptance? Best wishes Markus Malkusch [1]: http://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#addSuppressed-java.lang.Throwable-