Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91636 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1387 invoked from network); 11 Mar 2016 15:41:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2016 15:41:43 -0000 Authentication-Results: pb1.pair.com header.from=pierrick@webstart.fr; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=pierrick@webstart.fr; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain webstart.fr from 209.85.161.174 cause and error) X-PHP-List-Original-Sender: pierrick@webstart.fr X-Host-Fingerprint: 209.85.161.174 mail-yw0-f174.google.com Received: from [209.85.161.174] ([209.85.161.174:36033] helo=mail-yw0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/10-00836-637E2E65 for ; Fri, 11 Mar 2016 10:41:42 -0500 Received: by mail-yw0-f174.google.com with SMTP id g3so96790902ywa.3 for ; Fri, 11 Mar 2016 07:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=webstart-fr.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:cc; bh=GDZzWf8rveAjzLUMXUCzfKYijH5X+7B5hIba4/Xt2W8=; b=Zqavuw8uoVkBPerxgZigaccVdoXT7RQplvQrqUVQU1jSMMvlWbongCrIOZIXUOOkPd omtAqHYrCuQJ7liiKvSZ8YLoYKTHjhG3WgdTMMtz+vge3MnP8E2ObLGyMzPpDylGNLiR R22pG/4+7p/BSQBCzjxyDB0RldypEmF+RgncrlwLc0PHcZBOdZWp1qx6s4rNsLJepOMy KUOJs6qPi5RQOOd/rX6ypCJPuMfw7sjDGq7/8EFLw1OGqNfUR4fSqf2YSYDnlqVTqg52 d9AkqK6PGXvAuvS1DLOGS8jb0+My8U+O1uh8k/izL7RG3jupXYbU5Pu2mzvW8wfpN0OP jguQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:cc; bh=GDZzWf8rveAjzLUMXUCzfKYijH5X+7B5hIba4/Xt2W8=; b=CoQQCcL3actTOWl+bnha2bVBkeMypWY2CSwVCwt6hppVxG9idXo7E1qBrQF39+tVgs Try4C5m+mH9GDa0wemAN16Neh1OmaS/8hNAgV/DIh/fvt9XqnBtD6uU0efyNv6aueM6t YUsMGy5yvVR1ic2r+5xC4O9GOzDY09Dn2A7TYFhFWFo4KTb38PPH0VYFPsejeSo12akE BpNgPyaryJCTSJc/NiUBn4i4L005dBzp2MrhIZx6MFRKfkUJGUBsfv4MIqvrxISl1TpC QZYEcpSWwxKP2/5Ug+zHVKFGYOb3Y6JHH+zLjupBh1TVSM4OHuAgGQHT1HH+bznNVqZS IVeA== X-Gm-Message-State: AD7BkJKAnQPtSeCcXz9IURLsCqIik/RG0yKcK5dvTKnOMXKB3vRyzbST65PC26EeMIYL/JLg0IGMd69MGjcPkQ== MIME-Version: 1.0 X-Received: by 10.13.212.204 with SMTP id w195mt6394687ywd.156.1457710899791; Fri, 11 Mar 2016 07:41:39 -0800 (PST) Sender: pierrick@webstart.fr Received: by 10.37.76.130 with HTTP; Fri, 11 Mar 2016 07:41:39 -0800 (PST) In-Reply-To: <56E122B7.5080407@telia.com> References: <56DF5B04.1080505@telia.com> <56E122B7.5080407@telia.com> Date: Fri, 11 Mar 2016 10:41:39 -0500 X-Google-Sender-Auth: diLEGpXAeJjDMBRVYkjMpG63qGo Message-ID: Cc: =?UTF-8?B?QnJvbmlzxYJhdyBCaWHFgmVr?= , PHP internals Content-Type: multipart/alternative; boundary=001a114fbd385fa628052dc7c452 Subject: Re: [PHP-DEV] [RFC Discussion] Catching multiple exception types From: pierrick@adoy.net (Pierrick Charron) --001a114fbd385fa628052dc7c452 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks for your feedback ! Any other thoughts from anyone else on this ? On 10 March 2016 at 02:31, Bj=C3=B6rn Larsson w= rote: > Hi, Thanks for clarifying. Think the RFC would benefit from having > some of these examples in it. I also had in mind that it's handy for > catching many exceptions when logging stuff and re-throwing like: > > } catch (FirstException | SecondException ex) { > logger.error(ex); > throw ex; > } > > Regards //Bj=C3=B6rn > > PS Sorry for top-posting... > > > Den 2016-03-09 kl. 08:05, skrev Bronis=C5=82aw Bia=C5=82ek: > >> 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/exception= s, >> // 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 >>> for >>> MY needs. But if someone already had to do this fill free to provide yo= ur >>> 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 >>> doctrine >>> 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 abo= ut 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 >>>> >>>> >>> >> > --001a114fbd385fa628052dc7c452--