> -----Original Message----- > From: Prabath Kumarasinghe [mailto:prabath321@xxxxxxxxx] > Sent: Thursday, February 21, 2008 11:19 PM > To: php-general@xxxxxxxxxxxxx > Subject: Exception vs exception > > 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 Class names are case insensitive, so "Exception" is the same as "exception". Now, about the first approach: Does the mysql extension throw exceptions??? (maybe you just didn't write the throw statement, I presume). About the second approach: What is "catchc"? (I guess it's just a typo). And, what other exceptions are you expecting to be thrown out of the try block to use the second *generic* catch? If you and only you are throwing the custom * MySQLException* exception (which you should code and throw under the proper conditions) why do you need a generic *Exception* catch block? Regards, Rob Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 | TEL 954-607-4207 | FAX 954-337-2695 | Email: info@xxxxxxxxxxxxx | MSN Chat: best@xxxxxxxxxxxxx | SKYPE: bestplace | Web: bestplace.biz | Web: seo-diy.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php