Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62095 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78153 invoked from network); 9 Aug 2012 05:33:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 05:33:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; 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:47982] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7E/F1-00812-C9B43205 for ; Thu, 09 Aug 2012 01:33:16 -0400 Received: by wibhn17 with SMTP id hn17so169503wib.11 for ; Wed, 08 Aug 2012 22:33:13 -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=Ubr/LujNWvWCnpUPKN5iM44MToOjFC8zTUE9VK03dHg=; b=HH8eBt+lPR5ovl9dYZnGov6let/LysL+dZyUknQ9JQ/WS6UimAH0n356N4jAl73EnT qD1n4o+L/WFTpYsvUDLwvsdLRk1U75UvVFoOTWq1RC2pD2gpMFd0cPw8zP2SRBrhRQ3K /66ffwwtFui/B6oKivg/fomnMJECbw0XmiWGZW5i7/hHTBPyQwi7s2BrXclAvXiWv8Me uxD/8FjFV6KM7qLxu4y7sf6997cagsP+0r22d8EqI4XhE7gYNPTZ61S2gHYiuHVBOzGK FNi9qJHEzDR13mJ6u3CNK9vC78hl2Zh581QQhi0XPRrkYMw6mcfaZEpcWo5O21oiGq0l 2oeQ== Received: by 10.180.79.69 with SMTP id h5mr3860166wix.6.1344490392930; Wed, 08 Aug 2012 22:33:12 -0700 (PDT) Received: from pc (95-42-66-13.btc-net.bg. [95.42.66.13]) by mx.google.com with ESMTPS id fr4sm585474wib.8.2012.08.08.22.33.10 (version=SSLv3 cipher=OTHER); Wed, 08 Aug 2012 22:33:11 -0700 (PDT) Message-ID: To: "Stas Malyshev" , "Levi Morrison" Cc: "Ferenc Kovacs" , "PHP Internals" References: <501F46BE.4040407@sugarcrm.com> <50200FBD.2010506@sugarcrm.com> Date: Thu, 9 Aug 2012 08:33:01 +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: ALoCoQkIEySxoECQKm1iCdpIq343QxtzR15EIO33scoJhXQJuJme62XBFlP0F5VhNKHU02Dm2GvQ Subject: Re: [PHP-DEV] Error handling brainstorming From: sv_forums@fmethod.com ("Stan Vass") > Hi! > >> Because checking that the returned variable is `!== FALSE` is *way* >> better than throwing an exception, right? > > Yes, it is. You can control it, unlike the exception which you can not, > unless, again, you wrap everything into try/catch on every kind of > exception possible. Have you stopped for a moment to think this opinion through? Look at two typical patterns of error handling. The examples below are generalized from my file cache code. Having no cache is exceptional, because 99.999% of the time I run this, there is cache, except the first time when there's not. Tell me again how you using try..catch is very verbose and how you need to supply multiple catch blocks for "every kind of exception possible"? With exceptions: ---------------- try { fileop1(); fileop2(); fileop3(); normal_actions(); } catch (IOException $e) { exceptional_actions(); } Without exceptions: -------------------- $valid = true; if (fileop1() !== FALSE) { $valid = false; } if ($valid && fileop2() !== FALSE) { $valid = false; } if ($valid && fileop3() !== FALSE) { $valid = false; } if ($valid) { normal_actions(); } else { exceptional_actions(); }