Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91587 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70837 invoked from network); 9 Mar 2016 13:27:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2016 13:27:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=arvids.godjuks@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=arvids.godjuks@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.182 as permitted sender) X-PHP-List-Original-Sender: arvids.godjuks@gmail.com X-Host-Fingerprint: 209.85.217.182 mail-lb0-f182.google.com Received: from [209.85.217.182] ([209.85.217.182:36538] helo=mail-lb0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/13-53667-CD420E65 for ; Wed, 09 Mar 2016 08:27:57 -0500 Received: by mail-lb0-f182.google.com with SMTP id x1so65191330lbj.3 for ; Wed, 09 Mar 2016 05:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VQRqupqKCMFVoQodUmywrg4XCZ0jZRH/qY9Bf1L5cFU=; b=ejjT+bmtNvglJ7n51jmrOaDx5ueK57fQzR1AwTkS8FyV2doMkcWUMY9QhPji/Qj2pW 1OKhitHiBU7Be6iwr4D+UWUxwtLb5s/LMMjFHoLOtVVsndiUERvLYAXw7RPATdbWf0wY akaeKReTPKsRapvfX8LaVMSxceQLbS83ZraESnaI9LBvDrB/IB+gCShPDxEfSIOE8rHF 8VHSViFoD6capUpJB7yVVwRH5g+i4ksq13hrcXuD3xgjpKVc/rbYcoukXneKxl1hbddb tk3yphqYqL9pLUEzF23xDMp1RCO8lBn0GvnZYTNCMmsuSjtLV3XprDeXNthrlgHVC1Ee dYHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VQRqupqKCMFVoQodUmywrg4XCZ0jZRH/qY9Bf1L5cFU=; b=QuuO8/dFFU+HCVKbGoPwKAp/vbU5+WtsxX0W3IEiKB2leJVzDqmGJTrcEbWGQXa4qt wd7DKYeruQ63usR3aNVRHc/hsCpoA4M5qv+b4RGSDAAqKFAu6OVC+LhvSUW1Bxdl4Gea mJyBRqwgoAIuVRgsMNseB6Jb8lmZoOVAJQUeeBP34nkfsQUzeMLoL79n5eFnbuTAdpId Ib9T1cH2mU39Eq65vZj37O81Oj0MDVuDRLvBeJTDSZWXOikbvPVxygYJmKdXM9YKFxWO XmQuAM9uyT3p5rZhHrxgRNXRi6g186I0ahg69itmfFI60kgAm2PV0y+5HGLXIXMByPCV lR3w== X-Gm-Message-State: AD7BkJJv2FCTWUiYLqcXNjBJHFouETVSjmLc+8Gs+haYiCPC4yKRK7Z+zzfhcUhDpEfrjYH2GaUICLWDCVm6pQ== X-Received: by 10.112.139.104 with SMTP id qx8mr11581096lbb.88.1457530073790; Wed, 09 Mar 2016 05:27:53 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 09 Mar 2016 13:27:44 +0000 Message-ID: To: Pierrick Charron , Marco Pivetta Cc: Derick Rethans , PHP internals , =?UTF-8?B?QnJvbmlzxYJhdyBCaWHFgmVr?= Content-Type: multipart/alternative; boundary=089e0115fb8e4c411a052d9daacd Subject: Re: [PHP-DEV] [RFC Discussion] Catching multiple exception types From: arvids.godjuks@gmail.com (Arvids Godjuks) --089e0115fb8e4c411a052d9daacd Content-Type: text/plain; charset=UTF-8 I'm definetly lately started to use instanceof to check the type of exception I've got and throw further those that I don't need. This is especially valuable for CLI applications (I have a few daemons in PHP). So a big +1 on the proposal idea, as for the tech part - maybe unions is a good idea. Arvids Godjuks. On Wed, 9 Mar 2016, 15:24 Pierrick Charron, wrote: > 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/ > > > > > --089e0115fb8e4c411a052d9daacd--