Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92614 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22956 invoked from network); 21 Apr 2016 22:10:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Apr 2016 22:10:55 -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.173 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.161.173 mail-yw0-f173.google.com Received: from [209.85.161.173] ([209.85.161.173:36803] helo=mail-yw0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/88-14036-FEF49175 for ; Thu, 21 Apr 2016 18:10:55 -0400 Received: by mail-yw0-f173.google.com with SMTP id o66so104518107ywc.3 for ; Thu, 21 Apr 2016 15:10:55 -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=GU/YXJ6UUbMHokZW1y2bib3vjBlbi2cQb3lwjxzVBw4=; b=UZZ19btHXCl0Lywfd009fqP2nSkYzuZXGOqgYGKGYnRscOpGHgj5A76YFASMShqSCC dYzL7soy44PKNscA846so0E5exD6tm1irF9wHKOzDwu7eOHVt1KrUK7ecbLNYs8L9nCt cK42+rYHqhdO1P4FWVJsHEAQqdleM2+WHtefdyV8Pb29/G+KulA/AWcMkHoRdOp1Gdig NGFY7EaHoGsmeroUhnfjcQ9CQEBLEwShH0gdnGfA5+PuD8cNZmkOCVCFk499Uo1WaMSi MSQJ9a6RJi44VRhVrdngBRwD2SchaSywSnt15amQxRlHwFr21Y4epKCsF+xxPl/y5YN+ ictw== 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=GU/YXJ6UUbMHokZW1y2bib3vjBlbi2cQb3lwjxzVBw4=; b=ZLjSpJ0J1J/Sx1nCfv0SvRt6C5YEQg1+pIjBi25oqNzTkBvf/R2eaDsnpFQbcrEoGi wnykjt7AcuJNsaMmoCaejp4XAgQE5ELIDVeiAWLkSA3xQpbWTnWhC3Ur6ylx62tsAwrw gRZhpe3T3yjLzn1pudjyOUjUsHni22r+JmUWIHEI5a5UXC9O642lsk02z6Bpn9tBbNkM 4RoSSBZB+pMMGy5VI+kFFzc/ddG3afioPqY2PUKj01orky6iAVn+er7nMbXc7Ayvz6jz SuJttFvriBjLrLHYjWbD+0dTCMoZ/PULONYjZ7v3LNb3r5OWdTAtc7mXROxfF0YSFIRq oKxw== X-Gm-Message-State: AOPr4FVIRySn0Y84UDvHz47jYKOx8nb1bOAdd92GU/bfN+D4qhYvXIyGjZ+yyLCjNUbC6S2jmoTTMSqy3kVBZg== MIME-Version: 1.0 X-Received: by 10.129.154.79 with SMTP id r76mr11839903ywg.86.1461276652692; Thu, 21 Apr 2016 15:10:52 -0700 (PDT) Received: by 10.37.89.6 with HTTP; Thu, 21 Apr 2016 15:10:52 -0700 (PDT) X-Originating-IP: [78.145.242.188] In-Reply-To: References: Date: Thu, 21 Apr 2016 23:10:52 +0100 Message-ID: To: Patrick ALLAERT Cc: Zeev Suraski , Derick Rethans , Marco Pivetta , 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 20 April 2016 at 23:16, Patrick ALLAERT wrote: > It's also perfectly possible to make all those Exceptions implement a > "MatchingFailedException" interface (even empty). Apologies for continuing the conversation, even after the RFC is incredibly likely to pass, but; I don't understand that argument at all, and think I disagree with the philosophy behind it. If it was followed, it would mean that exception classes would need to be aware of how they are being used. When exception classes are defined in a library, and the exceptions are being caught in an applicaton, wouldn't adding applicaton specific interfaces to the libaries exception classes just violate the separation between the two? It doesn't seem to be good practice. It would also lead to multiple interfaces being added to each exception class. e.g. if in the application we had these catches in different places in the application: try { return foo(); } catch (ResourceNotFoundException $e) { return FALSE; } catch (ParamNotConvertedException $e) { return FALSE; } try { return bar(); } catch (ResourceNotFoundException $e) { return FALSE; } catch (AccessDeniedHttpException $e) { return FALSE; } try { return quux(); } catch (ResourceNotFoundException $e) { return FALSE; } catch (MethodNotAllowedException $e) { return FALSE; } Where we specifically want to catch ResourceNotFoundException and one other exception. If we followed your advice and added a specific interface to the exceptions for each of the separate combinations, so that we could catch just the interface we would end up with this: class ResourceNotFoundException extends \Exception implements FooExInterface, BarExInterface, QuuxExInterface {} i.e. having to add one interface per usage. That doesn't seem that great either....and again is altering a class based on how it's going to be used. > It encourages people to replace any kind of condition with an exception, > leading to less readable code and incomplete API. I don't think this is the right attitude to have when designing a progrmming language. Any feature that enables developers to write code that covers edge cases in their application is by it's very nature going to be possibly to use in a way most people consider inappropriate. It's much more productive to focus on making code/features that are useful when used sensibly. Worrying that people might use it in a way that you wouldn't recommend using it, is fundamentally the wrong problem to try to address when designing a language. I think that's true in general but particularly true in a language like PHP where one application might be programmed in a very different way to another application. What would be useful and appropriate for one of them would be could considered a horrendous hack* in another application. If we are limiting ourselves to adding features that are correct and appropriate to use in all applications, that is limiting ourselves to a subset of the features that people would want to have to cover all of their use-cases. cheers Dan Ack * For example, a lot of people strongly dislike annotations. A significant number of people use annotations in their applications. Neither groups is 'right' or 'wrong', but it would be wrong for the people who don't like annotations to say that annotations should never be used.