Re: Exception misinformation

From: Date: Wed, 07 Jul 2004 08:59:54 +0000
Subject: Re: Exception misinformation
References: 1 2 3 4 5 6  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-31700@lists.php.net to get a copy of this message
Stephan Wentz wrote:
Lukas Smith wrote:
Justin Patrin wrote:
I 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.
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...
Err I was trying to give an example of using an exception for control flow. I was certainly not suggesting that this is the way I would use exceptions or that Hans was suggesting to use them like that. regards, Lukas Smith smith@backendmedia.com _______________________________ BackendMedia www.backendmedia.com berlin@backendmedia.com Linn Zwoch Smith GbR Pariser Str. 44 D-10707 Berlin Tel +49 30 83 22 50 00 Fax +49 30 83 22 50 07

« previous php.pear.dev (#31700) next »