Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83207 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57821 invoked from network); 19 Feb 2015 15:28:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2015 15:28:01 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.178 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.178 mail-vc0-f178.google.com Received: from [209.85.220.178] ([209.85.220.178:51623] helo=mail-vc0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/DD-18870-00106E45 for ; Thu, 19 Feb 2015 10:28:01 -0500 Received: by mail-vc0-f178.google.com with SMTP id hq11so1357983vcb.9 for ; Thu, 19 Feb 2015 07:27:56 -0800 (PST) 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:content-type; bh=0lBKdmYBVhnVXlX9peNZcaBHVo3/WuCHK16gDSoWKoo=; b=hNWvPz1HiYWJSrxviVFneTWdri7GJkCHjAi7vA3aGvFPjnFeHUwAMsneOskxNatlSv HrQq1h7ocfppxhG6VWMNWtmp7VV39kox57AkI1rFBNLoj+oyYNE7ERGSgkFsbz7uCD1/ KvNPmdWgdlc+4+xS7BVMjzprVVa/My5kZh4PzBarHXwBdYEwH7C5U11SdGkcZ1YslwRW JqjYxXZ7JcD1ZgRCOR7GLMVGxgtTJFC2B+gUcnc6LbOwa/x6wQM9OQ7YQaDPZEjQY49n Z78/YBJa2kTnKyBDgC4pAhmfzeaQ2W4Xglj6xlNrMnxncOKu2znOayeIwf/X3WiiuH01 Kmuw== X-Gm-Message-State: ALoCoQnUEdvX0HFGEdQW8THnZEybyuOOwIS3zWF/4++haTVOsP+9SHstQT/w5d6u07XkAa8lr7c6sR/8pHSnOvvltAe8BZUSyz3mSytS+P4nXBkh4vRwU8E2zHWW5HxfHYKcjl9cglyCfmHVdOtMm7kSuYblfnlFuw== MIME-Version: 1.0 X-Received: by 10.52.52.136 with SMTP id t8mr2286014vdo.49.1424359676187; Thu, 19 Feb 2015 07:27:56 -0800 (PST) Received: by 10.52.74.73 with HTTP; Thu, 19 Feb 2015 07:27:56 -0800 (PST) In-Reply-To: References: Date: Thu, 19 Feb 2015 19:27:56 +0400 Message-ID: To: Trevor Suarez Cc: Dan Ackroyd , Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=089e0115f048882bfa050f7294d2 Subject: Re: [PHP-DEV] Re: [RFC] Exceptions in the engine From: dmitry@zend.com (Dmitry Stogov) --089e0115f048882bfa050f7294d2 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 19, 2015 at 6:14 PM, Trevor Suarez wrote: > I think that structure makes sense Dmitry. > > Though, just a bit on naming here (I know, its not a big deal, and naming > is hard, haha): > > I think that naming the new parent exception something like "Throwable" or > "Catchable" (as Nikita previously suggested) would be a bit more concise in > meaning than "BaseException". You may not have even meant that name as a > formal proposal, but I figured I'd weigh in regardless. :P > We thought about "Throwable" or "Catchable" interface, but this change would require more changes and will make more BC breaks. Thanks. Dmitry. > > - Trevor > > > On Thu Feb 19 2015 at 4:55:38 AM Dmitry Stogov wrote: > >> On Wed, Feb 18, 2015 at 10:30 PM, Dan Ackroyd >> wrote: >> >> > On 13 February 2015 at 23:25, Nikita Popov >> wrote: >> > > Subclassing: Should there be more specific subclasses of >> EngineException >> > > for particular errors? >> > >> > It's not obvious that any subclasses would be useful. However using >> > the code to specify the exact type of error, rather than having to >> > inspect the message would be good. >> > >> > > Should EngineException inherit from Exception (and as such be >> > > subject to catch(Exception)) or should we introduce some kind >> > > of special super-class that is not caught by default >> > >> > Even ignoring the BC problem with having EngineExceptions extending >> > Exception, I think the EngineException needs to be in a different >> > hierarchy to Exception to be able to write reasonable code in the >> > future >> > >> > Without having EngineException in a separate hierarchy of exceptions, >> > the code below will catch exceptions where the data is 'ok' but there >> > was a problem with the code, and continue to process items. This is >> > almost certainly not the correct behaviour when an EngineException has >> > been encountered. >> > >> > interface Service { >> > function foo($item); >> > } >> > >> > >> > function processData(array $itemsToProcess, service $service) { >> > foreach ($itemsToProcess as $item) { >> > try { >> > $service->foo($item); >> > } >> > // Because $service can throw an Exception that is specific to the >> > // implementation we have to catch \Exception, unless we are going >> > // to list all possible implementation specific exception types here. >> > // That would be a subtle case of strong coupling, and when a new >> > // implementation is made the new exception type would need to >> > // be added here. >> > catch(\Exception $e) { >> > // item was not processable but PHP engine is OK. >> > $item->markAsErrored(); >> > //Go on to process the next item >> > } >> > } >> > } >> > >> > >> > To avoid having EngineExceptions in a separate hierarchy, this >> > function could be converted to: >> > >> > function processData(array $itemsToProcess, service $service) { >> > foreach ($itemsToProcess as $item) { >> > try { >> > $service->foo($item); >> > } >> > catch(\EngineException $ee) { >> > //PHP engine is not stable - lets get out of here. >> > throw $ee; //or throw new ProcessException($ee) >> > } >> > catch(\Exception $e) { >> > $item->markAsErrored(); >> > } >> > } >> > } >> > >> > However that is bad as i)it's boiler plate to do the correct behaviour >> > ii) you have to remember to do that everywhere. Having to remember to >> > do the correct thing, is going to lead to people forgetting. >> > >> > It will still be necessary to catch all types of Exception in a single >> > catch block i.e. at the top level of a script to prevent exceptions >> > being shown to the end user. This could be made easier by having a >> > common super class for Exception and EngineException. However having >> > one try block that is required to have multiple catch statements to >> > catch all different types of exception is not that much of a burden: >> > >> > try { >> > runApp(); >> > } >> > catch(EngineException $e) { >> > handleException($ee); >> > } >> > catch(Exception $e) { >> > handleException($e); >> > } >> > >> > As that would be the only place it would be required to catch both >> types. >> > >> > TL:DR EngineException needs to not extend Exception, whether we need a >> > super class is not as clear. >> > >> > cheers >> > Dan >> > >> > -- >> > PHP Internals - PHP Runtime Development Mailing List >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> I think we may introduce the following hierarchy >> >> abstarct class BaseException { >> } >> class Exception extends BaseException { >> } >> class EngineException extends BaseException { >> } >> >> the existing code that caught Exception is going to be unaffected. >> New code may decide to catch engine exception in separate catch block >> (using EngineException) or in single block (using BaseException) >> >> Thanks. Dmitry. >> > --089e0115f048882bfa050f7294d2--