Re: Exception handling in PHP

From: Date: Thu, 07 Feb 2008 07:37:30 +0000
Subject: Re: Exception handling in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-268849@lists.php.net to get a copy of this message
Does that mean for every exception do we have to write our custom exception and describe it from our own message Cheers Prabath --- Paul Scott <pscott@uwc.ac.za> wrote: > > 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; > } > } > > > All Email originating from UWC is covered by > disclaimer > http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm > > ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs

« previous php.general (#268849) next »