Re: PEAR_Exception in CVS

From: Date: Mon, 21 Jun 2004 05:15:39 +0000
Subject: Re: PEAR_Exception in CVS
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-31001@lists.php.net to get a copy of this message
Hans Lellelid wrote:
Excellent! -- I'll throw PEAR_Exception in Net_GeoIP (and in other classes too; I like the added flexibility).
Would be cool if most packages adopt it. For example one could do at the top of his code: <?php require_once 'DB.php'; function mydie($e) { die($e->__toString()); } set_exception_handler('mydie'); ?> And code the rest as if exceptions were never invented.
Thanks for being open to incorporating suggestions!
Nah, thanks you for being open to give them :)
public function getCauseMessage() {
  $msg = '     ' .   $this->method . " at {$this->file} ({$this->line})\n";
if ($this->cause instanceof Exception) {
    return $msg . $this->cause->getCauseMessage();
} return $msg; } It's making my head spin a little, but that should still handle the recursion .... right?
Absolutely, seemed a little bit dumb to pass "himself" each time (fyi is now 'private'). See the latest ouput! PEAR_Exception occurred: Error message: Failed first Error code : 0 File (Line) : /home/cox/www/php5/test.php (30)
  Method       : test::first()
Nested Error :
    #test::third() at /home/cox/www/php5/test.php (45)
     Failed third
    #test::second() at /home/cox/www/php5/test.php (39)
     Failed second
    #test::first() at /home/cox/www/php5/test.php (30)
     Failed first
From other side, I'm thinking on constructor signatures. Nowadays we're used to just "re-throw" the same PEAR_Error, no need to attach more info to it, as would be with the current PEAR_Exception. Something like: try { throw new PEAR_Exception('Error Message', $code); } catch (Exception $e) { throw new PEAR_Exception($e); // <-- } Some other minor commits are in CVS already. Tomas V.V.Cox

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