From: Michael S. <m-s...@us...> - 2005-09-12 18:07:48
|
Hello, On 09.09.05, Joerg Lehmann wrote: > On 09.09.05, Andre Wobst wrote: > > On 09.09.05, Michael Schindler wrote: > > > Is an exception the right thing to use here? I tend to dislike the > > > try...except notation and am not quite sure how efficient this is. > > > On the other had, with the different return types "float" or "None" > > > one always has to ask for the proper return type. > > > > Right. And in that sense such an specific exception is fine. And AFAIK > > (at least as long as exceptions do not occur very often), it is fine > > to use them. The overhead of the try-block is small (again AFAIK). > > Python's exception handling is very efficient. Furthermore, it's good > practice to use exceptions instead of returning arbitrary marker values > like None in cases where a result cannot be obtained due to some > "exceptional" (ahem) condition - at least, as a rule of thumb, there are > always exceptions, of course ;-) There is something else that judges against raising an exception, in favour of the "arbitrary marker value": We calculate curvatures and rotations ... always for a list of parameter values. If one of them makes problems, you will never find out which one of them it was and you cannot do anything against it. The outcome would be that the user (or the module that uses this feature) has to ask for one parameter value after the other in a try...except block. Michael. -- "A mathematician is a device for turning coffee into theorems" Paul Erdös. |