Re: Exception handling in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux