PEAR_Error using

From: Date: Fri, 07 Jun 2002 06:51:26 +0000
Subject: PEAR_Error using
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6774@lists.php.net to get a copy of this message
Morning Boys A big blame for some pear dev(ils) While working on the docs, i see that PEAR_Error is regulary used for error handling, ok - good. But often i found such code like this: ----------- $fp = @fsockopen($nntpserver, $port, $errno, $errstr, 15); if (!is_resource($fp)) { return $this->raiseError("Could not connect to NNTP-server $nntpserver"); } socket_set_blocking($fp, true); if (!$fp) {
    return $this->raiseError('Not connected');
------------- Hm, wouldn't it increase usabilty, if you start writing more descriptive error messages? Especially the second message? And unbelievable, raiseError and the constructor of PEAR_Error support a second parameter called "error code", a integer number. Numbers are better if want to check which occurs: if( 1 == $error->getCode()) .... then if( "Not connected" == $error->getMsg()) Also the two function expectError and popError requires a error code, not message! And at the moment, a lot of Error objects contains 'null' as error code (default), so you can't really use this functions. Another ugly behavoir is passing the failure message i.e. of a server directly to the user: $r = $this->command("GROUP $newsgroup"); if (PEAR::isError($r) || $this->responseCode($r) > 299) {
    return $this->raiseError($r);
The normal user hasn't a list of possible server responses, in this case of a news server, so he didn't know what could happend and how to handle errors. And btw. why not: return $this->raiseError($r, $this->responseCode($r)); ?! This would programmers life make much easier. And at the end: Please write the possible PEAR_Error Messages *and* Errocodes into the doc comments. Grepping it from source is */(Z&"§=) PHPDoc supports this keyword: @throws exception [, exception] ie: @throws PEAR_Error("Be prepared", 666) So boys, i want to see a lot of CVS-commits the next days, i wish you a nice weekend ;-)

« previous php.pear.dev (#6774) next »