Re: Call for Review: RFC for Error Handling in PHP5 packages

From: Date: Fri, 06 Aug 2004 18:13:13 +0000
Subject: Re: Call for Review: RFC for Error Handling in PHP5 packages
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32494@lists.php.net to get a copy of this message
On Fri, 06 Aug 2004 14:16:41 +0100, Sergio Carvalho <sergio.carvalho@portugalmail.com> wrote: > Justin Patrin wrote: > > > > > > 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. > Whoops, sorry, I guess that didn't register when I was looking through the text. Thanks for pointing it out. Consider my point moot. ;-) > 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). Yes, class hierarchies are better, but I meant more from a return vs. exception thing. > > > > > > > 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. Another good point, thanks for clarifying. I'll consider my objections explained now. :-) > > Cheers, > > Sérgio Carvalho > > > > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

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