Re: PEAR_Exception in CVS
| From: | Tomas V.V.Cox | Date: | Mon, 21 Jun 2004 12:31:54 +0000 |
| Subject: | Re: PEAR_Exception in CVS | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-31022@lists.php.net to get a copy of this message | ||
Hans Lellelid wrote:
PEAR_Exception occurred: Error message: Failed first Error code : 0 File (Line) : /home/cox/www/php5/test.php (30)Well, you have to see how getTraceAsString() looks like: #0 /home/cox/www/php5/test.php(37): test::third() #1 /home/cox/www/php5/test.php(28): test->second() #2 /home/cox/www/php5/test.php(59): test->first() #3 {main} Ours already do that plus some other stuff. According to http://www.php.net/zend-engine-2.php, a method TraceFormat() should be the way to go, but I can't get it called. Maybe we could go with this name instead of _getCauseMessage().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 firstCool -- very nice output. & yes private or protected makes more sense. I wonder if we want to make it optional to have full traces also as part of __toString() since Exception::__toString() does this? Maybe via static setting of the class (?) Maybe that would be overkill actually, as getTraceAsString() is pretty easy to call.
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 {But "bubbling up" doesn't mean a bastard die with uncaught exception? :)throw new PEAR_Exception('Error Message', $code);} catch (Exception $e) {throw new PEAR_Exception($e); // <--} Well, we could do that too. I wasn't sure if there was a lot of value in that. I know there's some overhead to adding try/catch blocks so, I tend to avoid that and let the errors bubble up.
On the other hand, sometimes for consistency you want to re-throw your exceptions so that they are all of a certain class. Catch a ReflectionException and re-throw as PEAR_Exception, for example.Ah, good. Btw, how the hell can I add reflection support to my php? (using latest cvs here), missed it a lot when wanted to reverse engenier the Exception class. Tomas V.V.Cox