Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62098 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83894 invoked from network); 9 Aug 2012 06:47:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 06:47:06 -0000 Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 209.85.212.176 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:42008] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/23-00812-8EC53205 for ; Thu, 09 Aug 2012 02:47:06 -0400 Received: by wibhn17 with SMTP id hn17so19196wib.11 for ; Wed, 08 Aug 2012 23:47:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:from:to:cc:references:subject:date:mime-version :content-type:content-transfer-encoding:x-priority:x-msmail-priority :x-mailer:x-mimeole:x-gm-message-state; bh=FxI28l6Y8kjci1xLaFvUlbARdCF5ksXqcvAfIS6AUOI=; b=lhFG56KxBvuFFieuBv/l5hI7jyDVkK0jZn781EkruodqXFZKqkU+Hb61hRjR6CBN6l SPWi7DXW/7sSWStfdjUXbndKqJxdORloIsPl3HKYE/zklHQ/N5Tl7y/3YWZfX7Bu6X1b SYvC2Pj1Et4v6f+py3QkpEG4ggT+nMlEKeK19C1yZfd3EAns4FxLZgobjbFht4dP10N0 y1LqSfkl39JSV6bV/NM78KPY+pHBBBSfvcNWu+o0/+MzNZnh49/l0/k9CPn5zC9zMbzK 2sb75rwh2kmCFV9mRQ3+cp6RShiyl0mgDewj7X5SFMZ4CIjowjf0hryceq+UBlFhpo2c UySQ== Received: by 10.180.79.69 with SMTP id h5mr236052wix.6.1344494821987; Wed, 08 Aug 2012 23:47:01 -0700 (PDT) Received: from pc (95-42-66-13.btc-net.bg. [95.42.66.13]) by mx.google.com with ESMTPS id dc3sm34830wib.7.2012.08.08.23.46.59 (version=SSLv3 cipher=OTHER); Wed, 08 Aug 2012 23:47:01 -0700 (PDT) Message-ID: <5D51773C7D9C4328908EF141AE4FA7E7@pc> To: "Stas Malyshev" Cc: "PHP Internals" References: <501F46BE.4040407@sugarcrm.com> <50200FBD.2010506@sugarcrm.com> <5023544B.3020003@sugarcrm.com> Date: Thu, 9 Aug 2012 09:46:49 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="ISO-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Gm-Message-State: ALoCoQny9iztdp8nR/tUuyjPXR7xn/1m8jhgcXHKW3RK3H8XUPt+ecmpWHewycYe7CCkIWERy4mL Subject: Re: [PHP-DEV] Error handling brainstorming From: sv_forums@fmethod.com ("Stan Vass") > You are either purposefully exaggerating or not doing it right. > > if(fileop1() && fileop2() && fileop3()) { > // do valid stuff > } else { > // do error stuff > } > > It's not that hard. I guess it was my mistake that I simplified my actual code for simplicity's sake. Please show me how would my actual code look stuffed in an "if" statement: try { $cacheBaseFile = Core\CACHE_PATH . '/Compiled/' . \str_replace('\\', '-', $symbolName); // The validator checks whether the cache is fresh. $cacheIsFresh = include $cacheFileBase . '.val.php'; // Attempt to load the cache (it should be there if the validator is there, unless someone messed with the files). if ($cacheIsFresh) { $result = include $cacheFileBase . '.main.php'; } else { $this->generateCache($symbolName); ... } return $result; } catch (IncludeIOError $e) { // One or more of the files were damaged or missing. ... } When you have: 1) comments 2) multiple statements 3) assign variables 4) call functions/methods with long arguments etc. ...you can't just stuff it in an if (op() && op() && op()) and pretend this is in any way a maintainable code style. >> With exceptions: >> ---------------- >> try { >> fileop1(); >> fileop2(); >> fileop3(); >> normal_actions(); >> } catch (IOException $e) { >> exceptional_actions(); >> } > > Now imagine fileop1 throws some other exception - note that you have no > idea which exceptions are there and nothing guarantees you fileop1 > throws only IOException, and by the proposal here, any problem in any > code whatsoever results in exception now, even if the problem was in > converting log message to utf-8 while writing some log inside some > function called by fileop2(). Now your whole app has failed, even though > you don't really care about that log message at all. Exceptions aren't about log messages, they're about exceptions - error conditions that have to be handled. If my code above generates another type of exception there are only two options: 1) Either I catch that exception because I know how to handle it -or- 2) I don't catch it, and the app should correctly stop right there before data damage is done. I know PHP's model is all messed up, but no one here, I believe, is asking about putting non-error log messages in Exceptions. IO failure is an exception. If your IO operation fails, you can't just log it and plow forward blissfully without handling the problem. Stan