Hi Paul

Is this following code work in PHP if mysql_connect
fails.

try{
mysql_connect('localhost','user','');

}catch(Exception $e){
  echo $e->getMessage();

}

Cheers

Prabath

--- Paul Scott <[EMAIL PROTECTED]> wrote:

> 
> On Wed, 2008-02-06 at 22:52 -0800, Prabath
> Kumarasinghe wrote:
> > Hi All
> > 
> > I'm little bit confusing with PHP exception
> handling.
> > Could you able to explain how to put try{} and
> > catch(){}  in a proper way in PHP. I had already
> read
> > php exception manual but it didn't help me to get
> > exact idea about exception handling in php.
> > 
> 
> Well, its pretty simple really...
> 
> In your objects that you create, just put in a
> statement that throws an
> exception of some sort (I like to extend the built
> in exception handler
> with a custom one that deals properly with db errors
> as well as PHP
> ones) and then try{} and catch(){} them in your
> business logic.
> 
> example:
> 
> class someclass {
> 
>     public function foo()
>     {
>          // do something
>          ...
>          else {
>              throw new Exception("uh-oh - we have a
> problem!");
>          }
>     }
> 
> }
> 
> $thing = new someclass;
> try {
>     $thing->foo();
> }
> catch(Exception $e) {
>     echo $e->getMessage();
>     exit;
> }
> 
> --Paul
> 
> > All Email originating from UWC is covered by
> disclaimer 
>
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm
> 
> 
> > -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

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

Reply via email to