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?
Throw exception in exceptional circumstances.
If the condition is something you expect in the normal run of the program, check for it and report an error. Reserve exceptions for things that should never happen, or as an indication to other programmers that something unrecoverable has occurred.
In your case, returning false
makes more sense (or perhaps use a null object as a return value).