Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62069 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76066 invoked from network); 6 Aug 2012 18:48:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Aug 2012 18:48:48 -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.173 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.173 smtp173.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.173] ([67.192.241.173:49143] helo=smtp173.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/24-03102-F8110205 for ; Mon, 06 Aug 2012 14:48:47 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp17.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id D25B2188284; Mon, 6 Aug 2012 14:48:44 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp17.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 552211884E0; Mon, 6 Aug 2012 14:48:44 -0400 (EDT) Message-ID: <5020118B.8070409@sugarcrm.com> Date: Mon, 06 Aug 2012 11:48:43 -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: Andrew Faulds CC: Amaury Bouchard , Ferenc Kovacs , PHP Internals References: <501F46BE.4040407@sugarcrm.com> <501FAD8F.2070600@ajf.me> In-Reply-To: <501FAD8F.2070600@ajf.me> 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! > Personally, I'm used to what other languages like Python do, and I think > it makes more sense. Exceptions mean you can try/catch the things your > code needs to be prepared for (non-existence, maybe), but other things No, they mean you need to *always* try/catch since you have to means to check if the downstream function can throw and exception or maybe call some other function that throws and exception. Exceptions propagate. In Java, you have compiler-controlled throws (which doesn't work in 100% of cases either - I regularly get exception messages from Eclipse, and this one is written by people with great knowledge of Java) - in PHP, you will have nothing. It's one thing when the code writes a warning and returns null when something unexpected happens, another when it throws and exception and you *have* to know which kind it will be and catch it - or just catch everything and ignore it (because you have no idea what it might be) and - check some success value then! > you haven't considered or are very unlikely, can just not be caught and > cause your code to halt execution. And it makes it harder to > accidentally avoid checking for errors and then wonder why $file is some > NULL or FALSE or other "error" value. How it makes it harder? If you forget to check the result, you'll as well forget to try/catch. It just makes the consequences worse - and remember, this all happens in runtime! -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227