Re: PEAR_Exception - some refactoring

From: Date: Sat, 28 Aug 2004 18:08:58 +0000
Subject: Re: PEAR_Exception - some refactoring
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-33005@lists.php.net to get a copy of this message
Hi Bertrand, Looks generally good - do you have commit access or would you like me to take care of it? Incidentally, I think people will need a getRawMessage() method to retrieve the error message for logging purposes (all that html won't look so good in a text file :) This would simply mean __toString() would call getRawMessage() if $_SERVER['REQUEST_URI'] doesn't exist. The only other note is have you tested creating an exception in the global context? I may be wrong, but I think getErrorMethod() would cause a notice of undefined index 'function', same with the getErrorClass(). Not that I would use this in the global context, but it might as well work for completeness in case someone finds a good reason to do so. Greg Bertrand Mansion wrote:
Hi, I have been working on PEAR_Exception and chaged a few things. You will find the new source there: <http://www.mamasam.com/pear/Exception.phps> Changes ------- - The constructor is lighter and should be faster: faster if/else, no getTrace in the constructor. - Got rid of $error_class, $error_method, $_method properties as their content is already available in method getTrace(). - method delObserver() -> removeObserver(): more comprehensive name - globals PEAR_OBSERVER_PRINT, PEAR_OBSERVER_TRIGGER, PEAR_OBSERVER_DIE become PEAR_EXCEPTION_PRINT, PEAR_EXCEPTION_TRIGGER, PEAR_EXCEPTION_DIE respectively, in order to conform to CS (there might be a PEAR_Observer class someday). - method _getCauseMessage() -> _getCauseMessage(array $causes) changed to a recursive method that fills an array of causes with arrays containing all the needed info for a informative cause message. Does not return a string anymore, just the raw data. - getErrorClass() and getErrorMethod() use the info avilable in getTrace() - And last but not least, added an html rendering as well as a more complete output for the __toString() method. The output now contains the hierarchy of all causes and a trace of where the exception was thrown. Depending on your environment (CLI or web) the output will be text or html (a table in this case). Both version contain the same info as the getTraceAsString() method, with causes messages added. - Added a getTraceAsHtml() method. I'd like to commit these changes to PEAR/Exception.php if that's ok with everyone. Please let me know how you feel about it and if you have any comments on the proposed code. Example: <?php require_once 'PEAR/Exception.php'; class Test
{        public function openFile($file)
    {
        if (!@fopen($file, 'r')) {
            throw new PEAR_Exception('Unable to open '.$file);
        }
    }
} $O = new Test; try {
    $O->openFile('not-existing-file');
} catch (PEAR_Exception $e) {
    echo $e;
} ?> Thanks, Bertrand Mansion Mamasam


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