How to except the unexpected?

James Stroud jstroud at ucla.edu
Sat Mar 4 22:40:36 CET 2006


Rene Pijlman wrote:
> James Stroud:
> 
>>Which suggests that "try: except HTTPException:" will be specific enough 
>>as a catchall for this module.
>>
>>The following, then, should catch everything you mentioned except the 
>>socket timeout:
> 
> 
> Your conclusion may be (almost) right in this case. I just don't like this
> approach. Basically this is reverse engineering the interface from the
> source at the time of writing the app.

This is using the source as documentation, there is no law against that. 
It's better than waiting for a closed source software mogul to 
benevolently give you the API documentation, which may not be 100% 
accurate itself.

> Even if you get it right, it may
> fail next week when someone added an exception to a module.

Given how all of the exceptions raised by both modules are either (1) 
builtin or (2) defined in the module itself and given that all 
exceptions defined in these modules inheret from a single class, my 
money is on the fact that this approach should be forward compatible.

> 
>>But it seems to me that working with the internet as you are doing is 
>>fraught with peril anyway.
> 
> Why? It shouldn't be.
> 

How things are and how things should be have always been 2 entirely 
different things. See early books by Robert J. Ringer for a more 
complete discussion.



More information about the Python-list mailing list