Re: Call for Review: RFC for Error Handling in PHP5 packages
| From: | Sergio Carvalho | Date: | Fri, 06 Aug 2004 13:16:41 +0000 |
| Subject: | Re: Call for Review: RFC for Error Handling in PHP5 packages | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32478@lists.php.net to get a copy of this message | ||
Justin Patrin wrote:
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Hmmm...there's nothing in Coding Guidelines like the following: You must use Exceptions for code errors.Under "Error Signaling in PHP5 PEAR packages" I state in the first paragraph that return codes are deprecated, and Exceptions are the chosen form of error signaling. Further down, I complement this, stating that whenever an error occurs, signaling via exceptions should occur. The end result is that whenever you see an Exception, there was an error, and whenever you detect an error, you must fire the Exception. However, feel free to edit the text and rewrite it in a more clear fashion. Writers tend to intuitively understand what they wrote :-)
Also, there's no mention of the possiblity of returning status codes instead of throwing an Exception. I mentioned that error *return* codes are deprecated. However, it might be interesting to mention that PEAR_Exception does support status codes if they're needed (although I believe class hierarchies are better that codes).
http://wiki.ciaweb.net/yawiki/?area=PEAR_Dev&page=RfcExceptionUse#toc27 IMHO, all failures should be required to be an exception. Return values for statuses may be used, but if functions such as checkAuthentication(), not authenticate(). If you call authenticate(), you're assuming the function *will* authenticate. If it fails, it is nto doing what the function says it will do....namely authenticate.That is wholly dependent on the description of the function objective: If you state that authenticate() will open a new authenticated session, then a failure to authenticate is an error, as the function is unable to recover by itself and do its defined job (open a new authenticated session). An Exception should be thrown. On the other hand, if you define that authenticate checks authentication credentials and returns true if they're valid, false otherwise, then a wrong password is just normal behaviour. It should return false. The definition of error condition should be clear on this. Again, if it is not, please go ahead and rephrase the text. Cheers, Sérgio Carvalho
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc