Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91586 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68730 invoked from network); 9 Mar 2016 13:24:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2016 13:24:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierrick@webstart.fr; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=pierrick@webstart.fr; sender-id=unknown Received-SPF: error (pb1.pair.com: domain webstart.fr from 209.85.160.179 cause and error) X-PHP-List-Original-Sender: pierrick@webstart.fr X-Host-Fingerprint: 209.85.160.179 mail-yk0-f179.google.com Received: from [209.85.160.179] ([209.85.160.179:34067] helo=mail-yk0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/92-53667-8F320E65 for ; Wed, 09 Mar 2016 08:24:08 -0500 Received: by mail-yk0-f179.google.com with SMTP id x17so20311754ykd.1 for ; Wed, 09 Mar 2016 05:24:08 -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:to:cc; bh=gCPSzFQ+w0gYmdycik+n5fbn8z+DbPZWcKL1YSD1pmc=; b=sOYYJl8u6YhTt0zUQgAXD/3COa3mW8QUcrwNnEYDcEUlWX/kWsFB3fIjXp9n38X4gk rNwnYvWhaeGbKjWsdBBxH5PJ8qDYlxag3YMrUtXc3mkMLieD9UkfuXME30RkYpSu+zkK XTX40CQCUaC8IhQdWlrTIBA9uCuJ8gjp+SvdDXV24t0+hODyejvP9vqdTJgcOn0jiuPx EufqlUoj0FKuAticX6JoDLf1G61yhMOO7Wpm4LmbNgyd6Z2QHeY8iSWGKcRh7R2LesQI EHObe93NQPVptRtJJL8+o/rBLTj8JjApRuROQl+lxC+jO9CGFdr4fnehv01GfPG7TTOg S7Dg== 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; bh=gCPSzFQ+w0gYmdycik+n5fbn8z+DbPZWcKL1YSD1pmc=; b=G+hT67JKFkDAf0JEGZzlRAvHfWv1C76VwD7RD/zibaJHOFxyn4ymjqeGUTAYNqKPOx 7BsbdYHedXNelRagbGNzzvml3twGFfE/DCe7280SORowEsvVYRQwdBpFhF7kk66Y93K7 Y3ZkcpqVQ4xVwFNFkttJVXWCwdS7Lz9Y3+yUNMwlY6+JAD91xxWDNZzxvG0+Vbk4f+G5 NetRf5K/xVO890susiQHclInN4jALk8bZCH+G7lMEgFStjAqSfiQEdLrTx+CN5v2vMpC ZEBpFMDIZtsaCZxDescf5AG02FZIyC1E6FbJnJiq4w1rkoO4zVM7YuJjhZYg/Z/tyS8P HM8A== X-Gm-Message-State: AD7BkJK2z1mzBiW7b9VvtKMpn7nKZSZslN5QD+7/coiQ8SKFYf1dCtjeCmsu4FjZyQipWY2I6FIiKGJy7qClog== MIME-Version: 1.0 X-Received: by 10.37.106.67 with SMTP id f64mr18826834ybc.89.1457529845523; Wed, 09 Mar 2016 05:24:05 -0800 (PST) Sender: pierrick@webstart.fr Received: by 10.37.76.130 with HTTP; Wed, 9 Mar 2016 05:24:05 -0800 (PST) In-Reply-To: References: Date: Wed, 9 Mar 2016 08:24:05 -0500 X-Google-Sender-Auth: 6msNTdY7NFEr6lKQ_Qvqpcgd5_4 Message-ID: To: Marco Pivetta Cc: Derick Rethans , PHP internals , =?UTF-8?B?QnJvbmlzxYJhdyBCaWHFgmVr?= Content-Type: multipart/alternative; boundary=001a113fc98ab164c9052d9d9c7e Subject: Re: [PHP-DEV] [RFC Discussion] Catching multiple exception types From: pierrick@adoy.net (Pierrick Charron) --001a113fc98ab164c9052d9d9c7e Content-Type: text/plain; charset=UTF-8 On 9 March 2016 at 08:08, Marco Pivetta wrote: > On 9 March 2016 at 14:03, Pierrick Charron wrote: > >> Hi Derick >> >> I agree that most of the time the best solution is to implement a clean >> exception hierarchy but as stated in the RFC : >> >> "A solution to fix this problem on the user level would be to implement a >> common interface for ExceptionType1 and ExceptionType2 and catch it. >> However, this is only possible when you control the exception hierarchy in >> your own code, but not possible when you don't control the code." >> > > I understand the use-case, but I don't see it as a widespread scenario. In > most cases, I've been doing something like following: > > I agree that this the RFC will not get the oscar for feature of the year, but I think it will lead in those few use-case to more readable code. > public function stuff() > { > try { > $this->willFail(); > } catch (FirstException $e) { > $this->handleFailure($e); > } catch (SecondException $e) { > $this->handleFailure($e); > } catch (ThirdException $e) { > $this->handleFailure($e); > } > } > > The thing I don't like about this approach is that I have to read the code and double check to make sure that the catch statement call the same method. For the amount of work that needs to be done in the Engine (see the patch attached to the RFC) this is far more readable and it is clear that the code to handle those 3 exceptions is the exact same one. And if the code of handleFailure is small you can even put it at this single place. public function stuff() { try { $this->willFail(); } catch (FirstException | SecondException | ThirdException $e) { $this->handleFailure($e); } } Even then, this is a rare eventuality, and as pointed out above, usually > fixed when wrapping exceptions correctly, if you have control over the > exception types). > Seems way below the 80/20 use-case to me, and introduces syntax changes as > well. > > Cheers, > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > > --001a113fc98ab164c9052d9d9c7e--