When to throw exceptions?
- by FRKT
Exceptions are wonderful things, but I sometimes worry that I throw too many. Consider this example:
Class User {
public function User(user){
// Query database for user data
if(!user) throw new ExistenceException('User not found');
}
}
I'd argue that it makes as much sense to simply return false (or set all user data to false in this case), rather than throwing an exception.
Which do you prefer?