Re: AW: [PEAR-DEV] Re: common error handling problem - a PFC issue?
| From: | Greg Beaver | Date: | Tue, 29 Jul 2003 03:41:38 +0000 |
| Subject: | Re: AW: [PEAR-DEV] Re: common error handling problem - a PFC issue? | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev php.pear.qa |
| Request: | Send a blank email to pear-dev+get-18863@lists.php.net to get a copy of this message | ||
Alexander Merz wrote:
Greg Beaver wrote:That's fine. Why 10? :)All errors returned must be based on an error code. This error code must be referred to only as a constant name, and never directly by the number code.An error code should be above '10' (just to be prepared...)
that's fine, I can understand this logic.Error constants shall follow the naming conventions for regular constants followed by "ERROR_". For instance, errors in the DB class must be prefaced by DB_ERROR_. All error codes must have an association with a default error message,ok.defined in a global variable that follows the naming conventions for a regular global variable. This global variable shall be an associative array, indexing error constants to error messages.+-0, see bottomFor packages that require internationalization, the array may either be replaced by error messages for another language, or itself contain arrays indexed by language code [Greg note: this should be the standard 2-letter code used by phpdoc, no? de, en, etc.].not ok If you want to provide localized error messages extend PEAR_Error and override getMessage()
I'm pretty sure I understand what you're saying here. The main reason an end-user developer might want to change the error message is to rephrase something to display it to a user, although this might make debugging difficult. The only part I am not sure I do understand is "should never lack to an application user," could you rephrase that? What does addUserInfo() do? the manual page says: Adds an user information to the error object. GregUnder no circumstances should a package ever directly access the error code by number. if define("DB_ERROR_FIRST", 1); is used, then references to DB_ERROR_FIRST must always be used, and never references to 1. This will allow future flexibility in error codes.okThis, by the way, is a perfect example of why some global variables should be made semi-public. If an error message is inappropriate to a particular product, it can be modified by an end-user without tampering directly with the original source.hm, an error message should give an developer (user of an class) a hint what happends and should never lack to an application user, i doesn't understand why you want to change messages text (BTW: don't forget the addUserInfo() method)