Re: Exception vs exception
| From: | Paul Scott | Date: | Fri, 22 Feb 2008 05:14:18 +0000 |
| Subject: | Re: Exception vs exception | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269838@lists.php.net to get a copy of this message | ||
On Thu, 2008-02-21 at 21:01 -0800, Prabath Kumarasinghe wrote:
> In second approach for every query I have to write
> throw new MySQLException("My Message"). It's very time
> consuming isn't it?
In order to *be* lazy, you have to *think* lazy...
Don't go and define every single query with an exception, thats just not
the lazy way, rather define a few functions that do generic stuff (or
even a single function that runs a query) and then send all of your
queries through that:
public function queryWithException($filter)
{
$results = $dblayer->query($filter);
if($results === FALSE)
{
throw new MyException("Query failed!");
}
else {
return $results;
}
}
then in your code:
try {
$this->queryWithException("SELECT * FROM users WHERE clue > 0");
}
catch (MyException $e)
{
// clean up
}
--Paul