Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91564 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19095 invoked from network); 9 Mar 2016 07:05:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2016 07:05:10 -0000 Authentication-Results: pb1.pair.com header.from=after89@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=after89@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.171 as permitted sender) X-PHP-List-Original-Sender: after89@gmail.com X-Host-Fingerprint: 209.85.217.171 mail-lb0-f171.google.com Received: from [209.85.217.171] ([209.85.217.171:34451] helo=mail-lb0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/15-15119-52BCFD65 for ; Wed, 09 Mar 2016 02:05:09 -0500 Received: by mail-lb0-f171.google.com with SMTP id xr8so50455082lbb.1 for ; Tue, 08 Mar 2016 23:05:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=KDnYxadL9fogJOZTH2TIZCztM3Bz+mFYKKzE8+yOxlM=; b=joosQK8o9OnVqVRwlfZ5gXC4jkMO7vwOdug0wNExFssLwbHpEiRz6IZ6rwHqODZcmb PLs2mIQ6yXnM8ytHwvWaebXF7Xc0X9e6Y6xhj+55J2wpcVTA6H1R6PMvPqkXg8YvhHxV YIMFoYHK0Cj0hoxUD5FimBy3DCBSPBKAQta2QvZOGz9P+oz2co5v2RMj+c7br2ZL8MvN UYKakZIfxHBHmUOKWG7G8K9q5WmyuEw+zPDDNipbaKYjBXH43nFaEVv/SKW7khzkmGfh +CMXLrYJw7fFLI1BL83xXsvlLLN0/gYdu/FSnjoydjCAdwKVEgxl4bKsLtqmRXIyi17Z 65cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=KDnYxadL9fogJOZTH2TIZCztM3Bz+mFYKKzE8+yOxlM=; b=WNti478Ksw0x1iuzXpETJA7u0Wxn7jjIvUrrO2bpCpnVVR6Fq9UOMSW3jbmzczy8HG U9x5UoZBSoTMMs7QJ4OFDXuZT8wniIxzrRTUKX/MYJ1PhOpGNdwbxZJqtJdOVHIX8GHX 7USHFJJUX3GBObEvLOPXhsOqZKr1qg0rjtPh3ZvFQz3vNMFESB5dgT9DpVBL94pACj+8 4DiU1pa2N3z1TcXMJcK9YSJlQVHa3JIUUcxkL1j9RJBDdVautrPECUJ21kddCGUN9qMi XBM+KqyX1XQN5WDC+3ukQnj7SIZbRw81JP/cybQ76onFfcPNZs27CVdRFlE1QRRTGc1P McTA== X-Gm-Message-State: AD7BkJLiqVUxNhT1g8yxwXBrneHSE9y12ehPFOwsv/qUY6yqo4TDl2xY4NBx3JQA+T9rfvsFcwIdD9hfD2VNjA== MIME-Version: 1.0 X-Received: by 10.25.212.213 with SMTP id l204mr11370045lfg.118.1457507105935; Tue, 08 Mar 2016 23:05:05 -0800 (PST) Received: by 10.112.208.4 with HTTP; Tue, 8 Mar 2016 23:05:05 -0800 (PST) In-Reply-To: References: <56DF5B04.1080505@telia.com> Date: Wed, 9 Mar 2016 08:05:05 +0100 Message-ID: To: Pierrick Charron Cc: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= , PHP internals Content-Type: multipart/alternative; boundary=001a1140c8ec4e98c9052d98515a Subject: Re: [PHP-DEV] [RFC Discussion] Catching multiple exception types From: after89@gmail.com (=?UTF-8?B?QnJvbmlzxYJhdyBCaWHFgmVr?=) --001a1140c8ec4e98c9052d98515a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi :) I think it is feature that is useful time to time, not very often. One example: class PackingFailed extends \Exception implements PackagingException {} // this exception could originate from package with assertions/exceptions, // so I cannot use common interface with above class EmptyName extends \Exception implements ValidationException {} class Packer { /** @throws PackingFailed */ public function pack(PackTemplate $packTemplate) : Pack { try { return $this->save($packTemplate); } catch (IOException $e) { throw new PackingFailed('', 0, $e); } } } class PackTemplate { /** @throws EmptyName */ public function __construct(string $name) { if ($name =3D=3D=3D '') { throw new EmptyName(); } } } /** @throws SomeException */ function packeForMe(string $name) : Pack { try { return (new Packer())->pack(new PackTemplate($name)); } catch (PackingFailed | ValidationException $e) { throw new SomeException($e); // or return null in other cases } } 2016-03-09 2:47 GMT+01:00 Pierrick Charron : > Hi Bj=C3=B6rn, > > The only time I had to do this with core PHP exceptions is to make the > code compatible for both PHP5 and PHP7: > > try { > } catch(\Exceptions $e) { > } catch(\Throwable $e) { > } > > But it will of course not be applicable since this feature is targeting > PHP7.1. Other than that the PHP core exception hierarchy is well enough f= or > MY needs. But if someone already had to do this fill free to provide your > use case as an example. > > My main target is custom exceptions (even if the logic is applicable on > everything Throwable). A custom exception use case would be some method > that throw thwo different kind of exceptions like for example the doctrin= e > AbstractQuery::getSingleResult (NoResultException, > NonUniqueResultException) that you could want to handle the same way. > > An other really easy example would be simple code like this one that I > found in symfony (not really a big deal but still) > > } catch (AccessException $e) { > return false; > } catch (UnexpectedTypeException $e) { > return false; > } > > And other piece of code using multiple libraries. > > > On 8 March 2016 at 18:06, Bj=C3=B6rn Larsson = wrote: > >> Den 2016-03-08 kl. 22:42, skrev Pierrick Charron: >> >>> Hi internals, >>> >>> Bronis=C5=82aw Bia=C5=82ek and I would like to start a discussion about= allowing >>> multiple exception types to be caught in a single catch statement. >>> >>> https://wiki.php.net/rfc/multiple-catch >>> >>> A working implementation and tests are available in the RFC. >>> >>> We are waiting for your constructive feedback and thoughts. >>> >>> Thanks >>> Pierrick >>> >>> Nice RFC! Think it would be good if you had an example in the >> RFC showing the applicability of catching two php exceptions. >> Especially given the new exception hierarchy in PHP 7. I'm also >> pondering if the main target for this is custom exceptions or >> the built-in ones or both? >> >> Regards //Bj=C3=B6rn Larsson >> >> PS >> > > --=20 Pozdrawiam, Bronis=C5=82aw Bia=C5=82ek. --001a1140c8ec4e98c9052d98515a--