Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89887 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77985 invoked from network); 24 Dec 2015 23:08:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Dec 2015 23:08:56 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.217.194 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.217.194 mail-lb0-f194.google.com Received: from [209.85.217.194] ([209.85.217.194:34724] helo=mail-lb0-f194.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/F0-51216-70B7C765 for ; Thu, 24 Dec 2015 18:08:55 -0500 Received: by mail-lb0-f194.google.com with SMTP id jk7so3013739lbc.1 for ; Thu, 24 Dec 2015 15:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=PsOtDG+93qB3221slQRtH/FclihgHu1kgkTZzDaK+lM=; b=mz+ilPotojubuJvIiDxolxDIJU75PL782ysdj7sRvAcUVeJ6MyuVvPrSXYkJd9i3Hp d9InGFBLCJIIGd4osCMLZyyC7Mw2ZITTSPqsLvzRZC27Cd2uhfGBh+kYOWYIHiBUQ056 6RogVM7TKwkH1104vxaFIml4/p9KqyU5vb1iAETTyCm9RNCQwH2aRXytW52PLdECiKat pnA+M1RvR6k/ukJuaY7veV0JJ0zz2kSLsBqhGSXH8X8kpjvMCuEbdiFDEozPbfootjnY xCwh0jq+40PTl/dy4C8mDCOhxpi0sbBuEtlMw2AOsqtpqtLBhNzSLDMw0Y3fmZQ1+kIc kSHA== 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:to:cc:content-type :content-transfer-encoding; bh=PsOtDG+93qB3221slQRtH/FclihgHu1kgkTZzDaK+lM=; b=CQLjKx86SJ968bfNWeZTi/zEYk86c1+tmZD3+robvBY1UXjgnESzgmwu9WQhaE25xS o01zRXZK+W8g8Ln6GKgRWUIPNFtNB/K8R2kxczuZaRmpbAYftZGdv85P42Pl1YCHltEC km8/tHjcBJyANccGKMtB7q6WY9kygkw8WBE/ArxFQfiv2m6laFe2zgMKCFohPSSvXO5v wKPnxeR6LEHt8RmOOda/Bev0goVxy5jtITdyz5gG0ev6WYH5IPz14056CTHzT8L4eSkE vVq8V44p+mF2Wr/krxlOx7fHMxV4cgQn3Pa0EV/qXq1s52lqywsa/ItmPzHcvulWhAJF hYmQ== X-Gm-Message-State: ALoCoQlokJrOZJO/khJOP+al7Bh6CZbcTIPp1+ct8CpdgV32T4uhl61uKhDZv7eaPLXuEPgsjprw77f1tICHL9ElvYIeD+dY6Q== MIME-Version: 1.0 X-Received: by 10.112.132.66 with SMTP id os2mr473089lbb.111.1450998531965; Thu, 24 Dec 2015 15:08:51 -0800 (PST) Sender: php@golemon.com Received: by 10.112.37.44 with HTTP; Thu, 24 Dec 2015 15:08:51 -0800 (PST) X-Originating-IP: [107.198.91.68] In-Reply-To: References: Date: Thu, 24 Dec 2015 15:08:51 -0800 X-Google-Sender-Auth: qIY1NGndzdEAJ5z0USVd2Y_8RTo Message-ID: To: =?UTF-8?B?QnJvbmlzxYJhdyBCaWHFgmVr?= Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Multicatch RFC proposal From: pollita@php.net (Sara Golemon) On Thu, Dec 24, 2015 at 2:40 PM, Bronis=C5=82aw Bia=C5=82ek wrote: > I've just created an RFC draft for catching multiple exception types > in one catch statement: > https://github.com/bronek89/php-multicatch-rfc > > I wrote RFC on github to check if there is any positive response from com= munity. > > Basically it introduces possibility to write code such as: > > try { > // ... > } catch (DbException | ResourceNotFoundException $e) { > throw new HttpException("not found", 404, $e); > } catch (\Throwable $e) { > throw new HttpException("fail", 500, $e); > } > > Provided patch is my first experience with PHP source code, so it > could be not perfectly written (or simply poor ;-) ) . > > What do you think about introducing that kind of feature into PHP? > I think introducing union types should be a prerequisite for this as we don't want the much more widely impactful feature of arg/return type hinting to be constrained by syntax we choose here (and making them inconsistent would be even worse). That said, from a general principle point of view, it certainly doesn't seem unreasonable. In an own-codebase one would probably use interfaces, have each exception implement the the common denominator (INotFound or what-have-you), but in a world of foreign components that's not always practical. On the other hand, one could just catch a throwable and use a pattern like = this: } catch (\Throwable $e) { switch (true) { case ($e instanceof DbException): case ($e instanceof ResourceNotFoundException): throw new HttpException("not found", 404, $e); default: throw new HttpException("fail", 500, $e); } } So I'm not personally going to get super excited about it, even if I would vote in favor. -Sara