Exception vs exception
| From: | Prabath Kumarasinghe | Date: | Fri, 22 Feb 2008 04:18:47 +0000 |
| Subject: | Exception vs exception | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-269828@lists.php.net to get a copy of this message | ||
Hi All
Recently I'm came across following code snippet
regarding exceptions there I'm executing invalid query
and catch the exception as follows.
First Approach
-------------------------------------------
try{
$result = mysql_query('SELECT * from unknowntable');
}catch(exception $e){
echo $e->getTrace();
}
-------------------------------------------
Second Approach
-------------------------------------------
try{
$result = mysql_query('SELECT * from unknowntable');
if (!$result) {
throw new MySQLException('Query failed to
execute')
}
}cathc(MySQLException $e){
echo $e->getMessage();
}cathc(Exception $e){
echo $e->getMessage();
}
-------------------------------------------
Which one is the best approach and efficient and what
the recommended approach.
Cheers
Prabath
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs