Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62097 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81522 invoked from network); 9 Aug 2012 06:10:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 06:10:25 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.163 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.163 smtp163.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.163] ([67.192.241.163:37851] helo=smtp163.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/B2-00812-F4453205 for ; Thu, 09 Aug 2012 02:10:23 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp6.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id DE92F27062A; Thu, 9 Aug 2012 02:10:20 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp6.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 6D469270903; Thu, 9 Aug 2012 02:10:20 -0400 (EDT) Message-ID: <5023544B.3020003@sugarcrm.com> Date: Wed, 08 Aug 2012 23:10:19 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Stan Vass CC: PHP Internals References: <501F46BE.4040407@sugarcrm.com> <50200FBD.2010506@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Error handling brainstorming From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > Have you stopped for a moment to think this opinion through? Look at two Of course not. Why would I bother thinking? It is always safe to assume nobody thinks before writing anything to the list. > 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"? 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. > 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. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227