Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92417 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46840 invoked from network); 18 Apr 2016 18:11:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2016 18:11:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.161.178 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.161.178 mail-yw0-f178.google.com Received: from [209.85.161.178] ([209.85.161.178:36208] helo=mail-yw0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/1A-11975-95325175 for ; Mon, 18 Apr 2016 14:11:37 -0400 Received: by mail-yw0-f178.google.com with SMTP id o66so211992999ywc.3 for ; Mon, 18 Apr 2016 11:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=+me+4V4NDEJdv+J33cPultRKWURROXHgrTjtx5wqDFI=; b=Ide3A0bAz9hL7YsVwGW76kzDshxX9VlRLDddqjhHl8jcDbWsqDyHuY8OP4Vn2jrtqM +cCiVyOZliLFq8ELCLOEK0vGfqg32BoVr89exEgE4QrhUDD1+yl6ek6dZ+gG2qEh2dwP rbKAAb1MHI7zOSDu7FnFgFPnhzIG3+IW2TfNgcBFWoVjTDRD8fRPOrzts409W/97UugR HdS9hh/QOHr+QDHAUAa52k7uGsFB2lGEXhY9oJu9BssnPO3k0eTb5opEKB6pnyfemoMp e2cIjcTzpiDew+22fbxJDAPd3KZcX9pWjlg4T0OqJkSWIRD0SBZllp3i9wbO3rvGsQqC 48Vw== 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=+me+4V4NDEJdv+J33cPultRKWURROXHgrTjtx5wqDFI=; b=DAecOGa9797HQEETlHrGiRe60eZGRXy9WoUjnEiYGkvm6eLopaDcwiVeAB//hXZnz+ mW1aXpXenBBSV6pGibypZtEQ/2XGJVJWqvfqfiMLySYuirykLbnrCwpyUmngxRy8uqqG hV2/S+ip5CIujtuR+BIiawQNo3ZLhzuofVf9Yz1gHcA5pPIAgr2ebuIyoNCb4O6XaKjw sjN4/q+/4+M9GrFdkB4nhkDi3GeIDXubzuTTy+ur8sxTYDeNbNQbbbSru8faDl5iQ012 dC9fSli/j9B84yH6wTZrRT8nJC6YAN2eN7yYHrVrYLZqBifWj/DKKEycJJpf5QmfA4E+ 2AQA== X-Gm-Message-State: AOPr4FVtoO3BNE/Tf5MLdY60vneM6B4QHEVgYMNLRnNQJZp/8KC4hyILSgNxSySUB4KcJ9/whyp3IWi/KVH9DQ== MIME-Version: 1.0 X-Received: by 10.129.116.11 with SMTP id p11mr20860752ywc.71.1461003093911; Mon, 18 Apr 2016 11:11:33 -0700 (PDT) Received: by 10.37.89.6 with HTTP; Mon, 18 Apr 2016 11:11:33 -0700 (PDT) X-Originating-IP: [2.96.88.216] In-Reply-To: References: Date: Mon, 18 Apr 2016 19:11:33 +0100 Message-ID: To: Derick Rethans Cc: Marco Pivetta , =?UTF-8?B?QnJvbmlzxYJhdyBCaWHFgmVr?= , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [VOTE] Catching Multiple Exception Types From: danack@basereality.com (Dan Ackroyd) On 18 April 2016 at 16:17, Derick Rethans wrote: > If they are user defined exceptions, you should make them implement an > interface, Even within one oranisation, getting different teams to agree to common interfaces is not always possible. But when the exceptions are originating in code that people don't have any control over (e.g. anything open source) then changing the exceptions to match your particular interface requirements is a completely impossible. For example will you and Marco start taking requests to add particular interfaces to any exceptions thrown by the code in the libraries you maintain? Derick wrote: > As you don't know which exception > class you have, how would you know how to handle each separately. Why do you think you need to know how to handle each separately? If you ever need to do something different based on the type of exception, you probably wouldn't be using the multiple-catch. The multiple-catch is almost only ever going to be used when you have a list of exceptions where you're going to be doing the same thing for each. e.g. for retrying an operation: $success = false; while ($attempts < 4) { try { foo(); $success = true; } catch (NetworkException | DBDeadLockException $e) { // Save exceptions to add to surpressed exception // when that RFC is hopefully passed. $attempts++; } // All other } //Check for success or run out of attempts here. For NetworkException and DBDeadLockException we're always going to do the same thing; retry the operation a couple of times. For any exception type where we would want to do something different......we'd just use a separate catch block. cheers Dan