Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83165 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72682 invoked from network); 19 Feb 2015 09:54:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2015 09:54:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.180 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.180 mail-vc0-f180.google.com Received: from [209.85.220.180] ([209.85.220.180:48223] helo=mail-vc0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/07-22021-4E2B5E45 for ; Thu, 19 Feb 2015 04:54:45 -0500 Received: by mail-vc0-f180.google.com with SMTP id im6so765804vcb.11 for ; Thu, 19 Feb 2015 01:54:42 -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=EUHGOEYAirG8vbaVA9/0WuPpYKyhjwRF/VR1+8JWQ0Q=; b=dyW2UZIciZQ2onDF471iXIZFiDmuRDs+S3Xh5hbSuuwcckSsSa0j595LTxT3QU5kl7 2mjsT6eBIIj1zROHa/0ezoq0aKe/qwkamBTL7xzi1q7gD4idVGQDyjCvD/+9JpaV8nWJ plYDbdKTg2oXJ2JCLHY/fAQDy6oZJEX/RhTChQzvvMRH+RqkFa0Lg5uwrQvahENTg0Lv YrMQpHUkroFU7X+3VM4MBp7Sp/+Dq0qzmms5Un50iy9OEpbTctMTgPcImXODZbJnEdES 06Z5T4w+XPb2bflK74s86YuQqi6ecnLzKSzjE4uzQVTbN5rRejpDpfrgeOcIfUd1DLno efFQ== X-Gm-Message-State: ALoCoQlfWnKwJPHaVF0VJTRt3KuobnfJxUnCuCrmCP2XuKdXD72dvMb+7tqowLn0Fow4hbXF6t8ulzjaRytHrEI8fyLroW+nbys6lNDwJGJcbpRdisxFuMMCByvIadx/9XcPesRkLERKT9WEfYXU6P1RogW32p//Cw== MIME-Version: 1.0 X-Received: by 10.52.51.198 with SMTP id m6mr1853558vdo.38.1424339681764; Thu, 19 Feb 2015 01:54:41 -0800 (PST) Received: by 10.52.74.73 with HTTP; Thu, 19 Feb 2015 01:54:41 -0800 (PST) In-Reply-To: References: Date: Thu, 19 Feb 2015 13:54:41 +0400 Message-ID: To: Dan Ackroyd Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=001a1136a0eac57d56050f6decf3 Subject: Re: [PHP-DEV] Re: [RFC] Exceptions in the engine From: dmitry@zend.com (Dmitry Stogov) --001a1136a0eac57d56050f6decf3 Content-Type: text/plain; charset=UTF-8 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. --001a1136a0eac57d56050f6decf3--