Re: Exception handling in PHP

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

 



// ...
That's from memory, so there may be a few errors.

Seems there was. Try this:

class DBException extends Exception {}

try {
    $connection = mysql_connect(...);

    if (!$connection) {
        throw new DBException('Failed to connect to database');
    }

// Database exception handling code
} catch (DBException $e) {
    // ...

// Generic Exception handling code (The Exception class is
// built in to PHP)
} catch (Exception $e) {
    // ...
}

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and Helpdesk software for £299 hosted for you -
no installation, no maintenance, new features automatic and free

             ** New Helpdesk demo now available **

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