When to throw exceptions?
        Posted  
        
            by FRKT
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by FRKT
        
        
        
        Published on 2010-03-31T18:02:52Z
        Indexed on 
            2010/03/31
            18:13 UTC
        
        
        Read the original article
        Hit count: 342
        
exceptions
|conventions
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?
© Stack Overflow or respective owner