Re: Error handling brainstorming

From: Date: Tue, 07 Aug 2012 00:55:45 +0000
Subject: Re: Error handling brainstorming
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-62075@lists.php.net to get a copy of this message
>> Because checking that the returned variable is !== FALSE is >> *way* >> better than throwing an exception, right? > > Yes, it is. You can control it, unlike the exception which you can not, > unless, again, you wrap everything into try/catch on every kind of > exception possible. > >> This type of thing is one of the main reasons I like PDO more than >> MySQLi. In MySQLi I'm constantly checking return values. In PDO I >> just wrap it all up one try/catch. It's not like if my query fails >> I'm going to try a different one. Most of the time it's just logging >> that something went wrong and reporting it upstream somehow. > > You are using exceptions for normal flow control. It is not what > exceptions should be used for. They are called exceptions for a reason. > It *should* be an exceptional situation if my database queries don't work properly. I've tested my code locally, on a staging environment and sometimes even ran tests on the live server. It is absolutely 100% an exception if something goes wrong, my friend. Opening a file? I have to agree that it should not throw an exception. I was replying more to explain the benefit of exceptions than to refute that one possible use-case.

« previous php.internals (#62075) next »