Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67846 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73422 invoked from network); 26 Jun 2013 08:01:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2013 08:01:32 -0000 Authentication-Results: pb1.pair.com header.from=florinpatan@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=florinpatan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.48 as permitted sender) X-PHP-List-Original-Sender: florinpatan@gmail.com X-Host-Fingerprint: 209.85.219.48 mail-oa0-f48.google.com Received: from [209.85.219.48] ([209.85.219.48:54443] helo=mail-oa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/D1-60917-BDF9AC15 for ; Wed, 26 Jun 2013 04:01:31 -0400 Received: by mail-oa0-f48.google.com with SMTP id f4so14268080oah.7 for ; Wed, 26 Jun 2013 01:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=vv7i1I1s4KKkz00MBek5QLri4/oo/SDX75RW1ZOwIWI=; b=GJttfNWN3gKRtOA7tlaYN1nv1kgieTz1gCxEPJgS3/NqysccDC63vFhq20W5aHOB+0 YiM0QoLoCe5au8YIhxKgluoxaUUHcSBe36EtwecAr9MDNlXV8iyGPTi+O/lCA/y1mNmd iF4RJMWHGuFsYGUPneAzmVjnbpxC0FGygrj11aJyQtsparnwO3LzzzVpCzMhjNS2Ggdb 9L39Ws2HYtKbwZK7wBAEMKWETYFgSb/eeMjuRyndEqAYFxKTftePyOEezJMhdTjLU17I TRyUtmr+F4dExf8d7/dXH4PK88a6lO4mhvHsvbHEGRKeoa0hbDKQDCTHsk/lHSziy4Su pvZA== X-Received: by 10.60.149.167 with SMTP id ub7mr1235247oeb.55.1372233688474; Wed, 26 Jun 2013 01:01:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.18.161 with HTTP; Wed, 26 Jun 2013 01:00:57 -0700 (PDT) In-Reply-To: <4ED7146272E04A47B986ED49E771E347BB4DF6F291@Ikarus.ameusgmbh.intern> References: <4ED7146272E04A47B986ED49E771E347BB4DF6F235@Ikarus.ameusgmbh.intern> <51C9DED2.5080401@sugarcrm.com> <51C9F485.6050709@sugarcrm.com> <4ED7146272E04A47B986ED49E771E347BB4DF6F291@Ikarus.ameusgmbh.intern> Date: Wed, 26 Jun 2013 10:00:57 +0200 Message-ID: To: Christian Stoller Cc: Stas Malyshev , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RE: Announcing RFC 'Anonymous Catches' From: florinpatan@gmail.com (Florin Patan) On Wed, Jun 26, 2013 at 8:31 AM, Christian Stoller wrot= e: >>> But I think it looks a bit cleaner if the variable could be omitted, >>> if it's not needed ;-) >> >> I don't think we need to change the language because Netbeans can't >> figure out how catch blocks work. > > The Netbeans thing was just an example/addition. > >> It's not used by you - which btw is usually not a good idea - if you've >> got an exception, you usually should somehow react to it - at least log >> it or something, that's what the exceptions are for, if the situation >> does not require special handling it shouldn't be an exception. But it > > If you have an exception like `BadCredentialsException` and throw it duri= ng authentication if the user has entered wrong login data, than you have s= uch a situation right? > But do you need any further information? No - in the catch block it may b= e enough to create a message for the user saying: "wrong username or passwo= rd". > > Maybe you only use generic exceptions like `RuntimeException`. This can b= e an exception for almost everything. But if you have defined an exception = for one special case, to interrupt your code, and catch such an exception y= ou will always know why this exception has been thrown. > -- > Christian Stoller > LEONEX Internet GmbH Hi, I believe that the example you provided, the one with 'BadCredentialsException', is a good example of a bad design and usage of exceptions, at least from my point of view. The fact that frameworks like Symfony2, Zend Framework or other php libraries/frameworks (ab)use the exceptions it doesn't mean that it's a good thing or you should have exceptions for everything. The provided example could just as well return false; for the login function and that's it, no? Exceptions should be used for exceptional cases where the application can't recover automatically from them. They are, even as their name suggests, exceptional cases, while a bad credential for a user login is not :) I also believe, and I might not be the only one with this, that exceptions used for flow control is a good sign of bad design. If you follow this way of thinking, everytime you throw an exception, you would want to catch it and perform some work with it, like logging it for example. So why would you make the variable optional then? Best regards ---- Florin Patan https://github.com/dlsniper http://www.linkedin.com/in/florinpatan