Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83200 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42347 invoked from network); 19 Feb 2015 15:14:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2015 15:14:26 -0000 Authentication-Results: pb1.pair.com header.from=rican7@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rican7@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.48 as permitted sender) X-PHP-List-Original-Sender: rican7@gmail.com X-Host-Fingerprint: 209.85.192.48 mail-qg0-f48.google.com Received: from [209.85.192.48] ([209.85.192.48:56865] helo=mail-qg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/5A-18870-2DDF5E45 for ; Thu, 19 Feb 2015 10:14:26 -0500 Received: by mail-qg0-f48.google.com with SMTP id a108so6748026qge.7 for ; Thu, 19 Feb 2015 07:14:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:from:date:message-id:subject:to:cc :content-type; bh=vU8NRC7qWz7W6NbIy1w79x207LcJKUTpOOW3T8txIkQ=; b=OrVZmJ28w2cJl0VyIwi7qjZNlyxlxBnb1gQJUkJOeWJAQqM1aOLCM1eNCjriiYLYez XCXmt3kyR71bsUVJAM6QIRC0l6IkuxwzdaTCEr72Y2qj3EjZYxxjHrvlVQ0dkIUPRi8X S2n4B5GU66gu0rTUDlsEAlyD75UOzKB1uGSr9OxPQ3y5dj0gBD2IrWmZYEU1ftXlshjl ImxJQuE3ahYy7mNiUo59+0niHHWLfS33iGsYTXnEqpzmYdWkLoenPJ9vN9AQt4IaBZ8j NYHKldAtGLr2VyEQdbBTnxE3DOfNU37WYIV00k7wkGC6FsE1TBwNb86kx4BSLTtf6EGh i1yQ== X-Received: by 10.140.233.84 with SMTP id e81mr13495528qhc.94.1424358863116; Thu, 19 Feb 2015 07:14:23 -0800 (PST) MIME-Version: 1.0 References: Date: Thu, 19 Feb 2015 15:14:22 +0000 Message-ID: To: Dmitry Stogov , Dan Ackroyd Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=001a11376eb211a213050f726413 Subject: Re: [PHP-DEV] Re: [RFC] Exceptions in the engine From: rican7@gmail.com (Trevor Suarez) --001a11376eb211a213050f726413 Content-Type: text/plain; charset=UTF-8 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 - 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. > --001a11376eb211a213050f726413--