Re: Re: PEAR_Exception in CVS

From: Date: Fri, 02 Jul 2004 08:35:04 +0000
Subject: Re: Re: PEAR_Exception in CVS
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-31482@lists.php.net to get a copy of this message
Alan Knowles wrote:
This thinking off the top of my head a bit, In general, PEAR_Exception at present is nice and simple, and looks like a good lightweight solution for most exception purposes. Missing from it: a) printf() type messages for arguments: (needed to enable translatable messages) Possible solution:? throw new PEAR_Exception("mymessage", MY_ID) throw new PEAR_Exception(array("my message %s",$somearg), MY_ID)
Umm, this would need to accept that params and accept something a callback for actually doing the translation no? Why not pass directly the translated string?
b) context exceptions (eg. per package) Possible solution:? MyClass_Exception extends PEAR_Exception { } or is this needed? - as debug_backtrace can grab the classname of the calling class?
It's implemented already $exception->getErrorClass() & getErrorMethod(), meaning "gimme the class or method where the exception was thrown". Is that good enough?
c) Stack? Could this be implemented seperately as a observer? d) Warnings etc. - just done by returning PEAR_Exception or a special contructor that flags the object as a warning? return PEAR_Extension::warning(....); (and hence MyClass_Extension::warning(....); )
After reading the post from Greg some posts ago, I'm starting to agree that stackable warnings/notices are a good thing. Oops, I'm remembering that needed that for File_CSV ;) As it's supposed that warnings/notices don't need to be handled and are just informative, what about: - A static method for pushing errors in the internal stack - A static method for getting the array of warnings - Ability to attach observers to warnings too. In short: class foo { function bar() { // code .. // grab the problem PEAR_Exception::warning('missing file', MY_MISSING); // rest of code } } PEAR_Exception::addObserver(PEAR_OBSERVER_TRIGGER); $foo = new foo; $foo->bar(); $warnings = PEAR_Exception::getWarnings($class = null);
Greg Beaver wrote:
My only concern is that all of the code and docs must be marked experimental with big "this may completely change at any moment" signs. Don't make the mistake PEAR.php 1.0 made and commit to BC too early. This is absolutely critical.
Don't worry, just needed a place for publishing the idea, I haven't added the class to the official package or shout to the winds "please start using that". It's just waiting for comments. Also would be glad, not seeing more error handlers, one unique way of error handling is the only way. Tomas V.V.Cox

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