Comparison with False - something I don't understand

Harishankar v.harishankar at gmail.com
Thu Dec 2 11:15:30 EST 2010


On Thu, 02 Dec 2010 15:53:49 +0000, Tim Harig wrote:

> 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.

I agree. But more specifically some exceptions seem too broad to catch 
specific errors that occur in MY code rather than in a system call or a 
library call. 

Also writing my own exception objects and raising exceptions seem to add 
too much of complexity to what is essentially a simple problem. This is 
what I was trying to explain.

> 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.

Doesn't the same finer grained exception mechanism make it prone to the 
same problems? 

Actually return values of functions which I write myself can be as 
specific and to the point. I could make it as fuzzy or as precise as I 
like. This is no doubt, something that I could emulate with an exception 
as well, but only make it slightly more complex with no obvious benefit.

As I said before, the way exceptions are caught seem to me to be the most 
confusing bit. Non-atomic operations always worry me. What if my function 
which is wrapped inside a try block has two different statements that 
raised the same exception but for different reasons? With error handling 
I could probably handle it right below the statement which was called and 
thus reduce the problem???

-- 
Harishankar (http://harishankar.org http://lawstudentscommunity.com)




More information about the Python-list mailing list