Re: Exception misinformation
| From: | Stephan Wentz | Date: | Wed, 07 Jul 2004 08:52:25 +0000 |
| Subject: | Re: Exception misinformation | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-31699@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
Justin Patrin wrote:Sounds like a really bad example ;-) If you call login() you receive true for a succeeded login, or false for a failed login. An exception would be thrown if the function encountered problems that hinder the function in returning true or false, for example because the database-connection went down. The function won't be able to check wether the login is right or wrong, and so it throws an exception. This is a big difference from just returning false because the login went wrong... I'd say that an exception should be thrown every time a function/method can't fulfill it's very own purpose. StephanI still wonder about this, though, as many experienced coders say that Exceptions shouldn't be used for code flow handling.Using exceptions means using exceptions as a straight forward goto. For example you call a method login() which checks the credentials of the user. Now you could throw an exception if the user is not logged in to send him to a different part of your code. Hmm maybe someone else can come up with an even clearer example. But a login method not being able to log someone in is usually not an error and certainly not an exception thing.