Re: What do you think which mode will be standard for PEAR Error handling in PHP5?

From: Date: Sat, 06 Dec 2003 06:52:31 +0000
Subject: Re: What do you think which mode will be standard for PEAR Error handling in PHP5?
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-9325@lists.php.net to get a copy of this message
But what happens if you first set PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION)? After this, the call to connect should throw an exception instead of a PEAR error when an error occurs. But what happens with internal calls in PEAR packages if you set the error handling to PEAR_ERROR_EXCEPTION globally? Will internal PEAR Package calls throw exceptions? If they do and the package cannot handle exceptions, PHP5 will stop executing and give an error saying that there is no catch statement. So setting error handling to PEAR_ERROR_EXCEPTION globally is not a good solution until PEAR packages can handle PEAR_ERROR_EXCEPTION internally? /Erik Jackson Miller wrote:
On Wednesday 03 December 2003 9:14, Michael Wallner wrote:
...so catch() replaces PEAR::isError()
Yeah, I get that part. But it seems to me that PEAR needs some kind of isError callback for all the code that is using PEAR modules. Within the modules it would all be try...catch, but take the following code as an example. While I don't think that we would need to worry about backward compatibility for the pear modules themselves, it might be a good idea to think about the users (though I could be biased on that one). <?php // include PEAR::DB require_once 'DB.php'; // connect to the database $myDb = DB::connect('pgsql://user:pass@host/database'); // check that the connection is valid if (DB::isError($myDb)) {
    die ($myDb->getMessage());
} // query the database $sql = "SELECT * FROM table WHERE col = 'value'"; $result = $myDb->query($sql); // check to see if the query worked if (DB::isError($result)) {
    // query failed
    $error = $result->getMessage();
} else { // process query results } ?> -Jackson


« previous php.pear.general (#9325) next »