some questions on PEAR_Error usage

From: Date: Tue, 24 Apr 2001 10:53:53 +0000
Subject: some questions on PEAR_Error usage
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-82@lists.php.net to get a copy of this message
I am developing a coding standard for our projects and I have several questions on the usage of PEAR_Error. 1. Should I create my own "exception" type subclassing from PEAR_Error. I know that PEAR_Error is somehow the current PHP's way of exception handling. But since there is no real exception ('try {...} except(ExcClass)') is it worth it to create my own ExcClass? And moreover, I can stuff whatever additional info on PEAR_Error's $message, $code, $options, $userinfo. 2. I want to set so that errors raised will print the error message complete with the originating object, the user info, etc. Any advice on how should I do this? 3. Should I just always use 'return $this->raiseError(...)' instead of 'return new PEAR_Error(...)' if my method want to report error? How do you guys find this style: function method() {
       if ($foo) {   // error!
            $this->error = $this->raiseError();
            return 0;   // false
       }
       return 1;
} ... if (!$obj->method()) {
       // handle the error
} over the current convention: function method() {
       if ($foo) {   // error!
            return $this->raiseError();
       }
       return;
} ... $res = $obj->method(); if (PEAR::isError($res)) {
       // handle the error
} (That is, the reporting method just returns 1/0 status so that checking error syntax is simplified). The actual PEAR_Error instance is available in $obj->error. Thanks, Steve

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