Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87477 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39774 invoked from network); 1 Aug 2015 01:25:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Aug 2015 01:25:59 -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:56522] helo=malkusch.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/00-38091-7202CB55 for ; Fri, 31 Jul 2015 21:25:59 -0400 Received: from f052009103.adsl.alicedsl.de ([78.52.9.103] helo=[192.168.1.90]) by malkusch.de with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.84) (envelope-from ) id 1ZLLYi-0001UV-Eo; Sat, 01 Aug 2015 03:25:56 +0200 Message-ID: <55BC201D.6010600@malkusch.de> Date: Sat, 01 Aug 2015 03:25:49 +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> In-Reply-To: <55BBD019.5030106@stephencoakley.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: Throwable::addSuppressed() From: markus@malkusch.de (Markus Malkusch) Stephen Coakley: > Interesting thought, but how is this different than including a previous > throwable and throwing a new, more descriptive exception? > > } catch (Exception $e1) { > try { > $resource->close(); > } catch (ResourceException $e2) { > // Pass in $e2 as the previous exception in the chain. > throw new ResourceFailedException($e1->getMessage(), > $e1->getCode(), $e2); > } > } Sorry, in my previous mail I actually forgot to answer your question. What you suggest is a common pattern to work around the lack of Throwable::addSupressed(). There are two big differences: 1) There's no causality between e1 and e2. You pass the message from e1 to the newly created ResourceFailedException which is caused by e2. Actually the causality here is correct, as ResourceFailedException is caused by e2. But what I understand is that ResourceFailedException should substitute e1 and e1 is not caused by e2. Just imagine e1 has the message "insufficient funds". Then the user gets an exception which says "insufficient funds" is caused by "could not rollback transaction". 2) You are loosing one stack trace (in this case from e1). For me the stack trace is the most important information in the exception. In this use case there are two stack traces and I want to have both of them. And then again this is just a simple example scenario with one resource. There might exist n resources. Markus Malkusch