Re: exceptions

From: Date: Mon, 10 May 2004 21:24:11 +0000
Subject: Re: exceptions
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-29061@lists.php.net to get a copy of this message
Hi, I whole-heartedly support the reservations expressed here. Exceptions are designed to be error-handling within constructors, and their use outside of that context is somewhat fuzzy. I think it is safe to say that ANY error that would require a trigger_error(E_USER_ERROR) should safely be shunted to an exception. In other words, if it was going to be fatal anyways, then making it an exception will actually improve both readability and the ability to handle the error in a controlled fashion. All non-fatal errors should never be made into exceptions - this includes errors that are created with PEAR::raiseError(), unless PEAR_ERROR_DIE is specified explicitly. Anyways, experimentation in non-stable php5-only packages is definitely a great idea. Regards, Greg Lukas Smith wrote:
Hi, well I slowly feel I have a concept of exceptions (thx george and terry for helping me along the way .. eventhough I still dont agree). i think until we have a clear understanding of exceptions and their good uses in pear we should refrain (exceptions being done on a case by case basis) from allowing them even for php5 only packages (actually while we are messing with the concept we should allow non stable packages using exceptions). anyways lets get a discussion going .. btw: if anyone knows a good introduction to exceptions in php please let us know since I am sure alot of people are very unsure that exceptions really are. Generally I see 2 decisions that need to be made: A general definition on how to deal with exceptions that dont leak out (1) and that leak out of a package (2). (1) Some people think that as long as exceptions dont leak out of a certain self-contained piece of code everything goes. Including using exceptions for code flow and messaging. I dont think we should allow this. It makes the code hard to read and maintain especially if you are not the original maintainer. Furthermore there is the danger of mistakes in the code making non fatal errors fatal due to an exception leaking out by mistake. So to me exceptions for code flow is like doing surgery with a shutgun. Sure some people might be more capable with a shotgun than with a scalpel. But then again maybe we dont want these people do to surgery on PEAR :-) (2) Here obviously code flow messaging is out. Actually this point also covers all uses of exceptions not mentioned in (1) .. heh a general comment like this seems dangerous .. someone please reorganize my comment if possible. Here are some examples: a) connect() b) login() c) find() d) do() for a) one might want to throw an exception if the server trying to connect to doesnt exist, since you are simply telling the class to do something. you dont really expect that to fail. however its a question if you also want to throw an exception if you simply didnt have the permissions to connect.. for b) a failed login() shouldnt throw an exception. since you are actually asking a question: may he login .. possible answers are yes and no. and so on .. regards, Lukas Smith smith@backendmedia.com _______________________________ BackendMedia www.backendmedia.com berlin@backendmedia.com Linn Zwoch Smith GbR Pariser Str. 44 D-10707 Berlin Tel +49 30 83 22 50 00 Fax +49 30 83 22 50 07


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