Comparison with False - something I don't understand

Tim Harig usernet at ilthio.net
Thu Dec 2 10:53:49 EST 2010


On 2010-12-02, Harishankar <v.harishankar at gmail.com> wrote:
> I am also wary of using larger catch-all try blocks or try blocks with 
> multiple exception exits (which seem to make tracking subtle bugs 
> harder). I prefer the philosophy of dealing with errors immediately as 

If you are using exceptions to try to catch bug then you are using them
improperly.  Exceptions (with the exception (no pun intended) of
AssertionError) are designed to catch error conditions, not bugs.

> harder). I prefer the philosophy of dealing with errors immediately as 
> they arise, rather than delegate them to exception mechanism. Of course, 
> I could wrap single statements in try blocks, but that makes the code 
> even messier without any significant benefits.

Actually, finer grained error handling commonly covers up bugs.  If you
want to find bugs, you want to make the program prone to crashing if
a bug is present.  It is all too easy to accidently mistake the return
value of a function as error condition and handle it rather the letting
the program crash.  By separating the results from the transmission of
error conditions (in effect taking error conditions out of band) then
you make it much harder to make such a mistake because you have to
explicity indicate which error conditions your code is capable of
generating.



More information about the Python-list mailing list