Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62061 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10786 invoked from network); 6 Aug 2012 07:43:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Aug 2012 07:43:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=amaury.bouchard@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=amaury.bouchard@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: amaury.bouchard@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:34573] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/86-03102-8A57F105 for ; Mon, 06 Aug 2012 03:43:36 -0400 Received: by obbwd18 with SMTP id wd18so6296984obb.29 for ; Mon, 06 Aug 2012 00:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=9ydYBUNBn4TQvawzzdTsRABOtiBV5arlUxJK8bqpICM=; b=frRmPDa+ZY++UqO/sH1mDYdpILUOT73/RpcHxcNez6HLqOg1ORPSR6ojwCw7j7P5tU PRWfu7S5e23vQttJwzQ8X8sc8Tfx5ozd1x/IPHsBkc/g6F79sgSeUrS0THnvmjAHVEpk QQOIk9mG58lXBiMXTQAvwvejmFofKe6pLBmMf0+QQEcHyqOST6ORX8Nd6iLDI7ku0qC7 B8hSIUCbBolbWjDmfz/DJPWcG4r66jF5opi4d+TfMzZP1TgGJfH7ibGnk0dXy9xI3f3J HMgSpaW7F7aX0UiynXZBDMIrI2eXkx1V7tFy8bTaoK5mBiS8k1txOKn5P6IUhBQhLnnD q0Bw== Received: by 10.60.24.4 with SMTP id q4mr17726631oef.50.1344239014044; Mon, 06 Aug 2012 00:43:34 -0700 (PDT) MIME-Version: 1.0 Sender: amaury.bouchard@gmail.com Received: by 10.182.149.69 with HTTP; Mon, 6 Aug 2012 00:43:13 -0700 (PDT) In-Reply-To: <501F46BE.4040407@sugarcrm.com> References: <501F46BE.4040407@sugarcrm.com> Date: Mon, 6 Aug 2012 09:43:13 +0200 X-Google-Sender-Auth: DNRUd294QmvgQCLALIShNsuRJ0U Message-ID: To: Stas Malyshev Cc: Ferenc Kovacs , PHP Internals Content-Type: multipart/alternative; boundary=e89a8fb20606ece53f04c6940884 Subject: Re: [PHP-DEV] Error handling brainstorming From: amaury@amaury.net (Amaury Bouchard) --e89a8fb20606ece53f04c6940884 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2012/8/6 Stas Malyshev > Exceptions are different from PHP errors. For example, if you try to > open a file and the file isn't there, throwing exception is a very > annoying behavior (yes I know some languages do that, IMO it's wrong). > The reason is that it's pretty normal and within normal set of > situations to which code should be prepared, so you will either have to > obsessively wrap everything with try/catch blocks or do exception typing > like Java does. Both options are quite annoying. I think it's much > better to just open file and check if the result is OK. Converting it to > exception doesn't really improve situation, as if downstream code didn't > handle it the upstream probably won't know what to do with that > exception either. This leads to code like try { whatever(); } > catch(Exception e) {}. I saw tons of that in Java. > Even a simple file opening can fail for different kind of reasons (the file doesn't exists, it is not readable, on some OS it could be already opened and thus locked). Most of the time, you don't care the reason, but sometimes you want to be more precise. With exceptions, we have an elegant way to manage all failures as a whole, or to differenciate each reason. But you are right, it could be very annoying to write a lot of try/catch blocks. Maybe we could think about something inspired from Lua's "protected call" function [1]. A convenient mean to say =ABOK, I know this expression may raise an exception, but I don't care, discard it silently please. I will check if my variable has been set or not.=BB. [1] : http://www.lua.org/pil/8.4.html --e89a8fb20606ece53f04c6940884--