Re: Exception handling in PHP

From: Date: Thu, 07 Feb 2008 10:48:58 +0000
Subject: Re: Exception handling in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-268860@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
If you mean "Do I have to write custom exception classes?", the no. You could just use the PHP Exception class. Eg. 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 c } catch Exception $e {
    // ...
} That's from memory, so there may be a few errors. -- 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 **

« previous php.general (#268860) next »