Re: PEAR_Exception in CVS
| From: | Hans Lellelid | Date: | Mon, 21 Jun 2004 13:37:19 +0000 |
| Subject: | Re: PEAR_Exception in CVS | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-31027@lists.php.net to get a copy of this message | ||
Tomas V.V.Cox wrote:
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().Does it really, though? The _getCauseMessage() method is displaying nested exceptions, but that is different from the call stack. That will only display a line for every time you re-throw. I think (as mention again below) that re-throwing is only for adding information to an exception & should not be standard practice. For myself, I like seeing the trace string, but I also have no problem typing $e->getTraceAsString() in my debugging code (or in logger now, etc.).
From other side, I'm thinking on constructor signatures. NowadaysNo, no -- just that there could be a number of call levels when an exception is thrown and perhaps only top level really cares about exceptions *anywhere* below. Certainly, you *must* catch exceptions in your code, but there's no need to explicitly catch & re-throw unless it adds information to the exception. Does that make sense?we'reused to just "re-throw" the same PEAR_Error, no need to attach moreinfoto 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); // <--}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.But "bubbling up" doesn't mean a bastard die with uncaught exception? :)
Oh, you should have it in your PHP5. The class names have changed to (e.g.) ReflectionClass instead of Reflection_Class (etc.) but should be there. Try <?php ReflectionClass::export('Exception'); ?> Not sure where the docs are officially for the Reflection API (in manual yet? too lazy to check :). HansOn 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.