On Wed, Jun 26, 2013 at 8:31 AM, Christian Stoller <stol...@leonex.de> wrote: >>> 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 during > authentication if the user has entered wrong login data, than you have such a > situation right? > But do you need any further information? No - in the catch block it may be > enough to create a message for the user saying: "wrong username or password". > > Maybe you only use generic exceptions like `RuntimeException`. This can be 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 you 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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php