Re: Exception handling in PHP

From: Date: Thu, 07 Feb 2008 07:15:46 +0000
Subject: Re: Exception handling in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-268848@lists.php.net to get a copy of this message
On Wed, 2008-02-06 at 23:10 -0800, Prabath Kumarasinghe wrote: > Is this following code work in PHP if mysql_connect > fails. > > try{ > mysql_connect('localhost','user',''); > > }catch(Exception $e){ > echo $e->getMessage(); > Probably not. I don't think that the mysql functions throw exceptions on failure. You will have to write a wrapper function to do the exception on failure, so something like function dbConnect() { $conn = mysql_connect('','',''); if(!$conn) { throw new Exception("Couldn't connect"); } else { return $conn; } }

« previous php.general (#268848) next »