Comparison with False - something I don't understand

Harishankar v.harishankar at gmail.com
Thu Dec 2 23:42:21 EST 2010


On Thu, 02 Dec 2010 16:52:57 +0000, Tim Harig wrote:

> If you are having that issue, then you are likely placing the try blocks
> at too low of a level in your code.  In general you will find that most
> systems have a gateway function as an entry point to the system. If
> there is not one already, then create such a function in you code. The
> parse function in my code above would be an example of such a gateway
> function.  Beneath that function, you don't need to know exactly where
> the error occured, you just need to know the nature of the error and
> have general error handling procedures for each kind of error that you
> expect might occur.

I think I might very well by using try blocks rather defensively rather 
than letting the code reach its logical conclusion in normal 
circumstances. This is why I think I find it a bit clunky. 

I think I understand the general trend of what you're saying. It 
definitely requires a mindset change. I still feel that user-defined 
exception classes might not be the way, but maybe I should allow the 
built-in exceptions which are thrown by library functions to follow its 
natural path upwards till it reaches the top level where it could be 
handled. 

Maybe I should handle the error only at the highest level (UI level) 
rather than returning False to flag errors. 

One of the reasons why I feared to do this is because I need to know each 
and every exception that might be thrown by the function and litter my 
top-level code with too many exception handlers.

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




More information about the Python-list mailing list