Comparison with False - something I don't understand

Tim Harig usernet at ilthio.net
Fri Dec 3 23:25:37 EST 2010


On 2010-12-03, Harishankar <v.harishankar at gmail.com> wrote:
> On Fri, 03 Dec 2010 14:31:43 +0000, Mark Wooding wrote:
>> In general, recovering from an exceptional condition requires three
>> activities:
>> 
>>   * doing something about the condition so that the program can continue
>>     running;
>> 
>>   * identifying some way of rejoining the program's main (unexceptional)
>>     flow of control; and
>> 
>>   * actually performing that transfer, ensuring that any necessary
>>     invariants are restored.
>
> my fault. Seems that exception handling requires a lot of forethought 
> since the control of program execution breaks at the point of exception 
> with no obvious way to rejoin it seamlessly whereas with an error, a 
> simple if condition could handle the error state and resume execution 
> from that point forward. This is the main reason why I think I used 
> simple error codes to handle certain recoverable conditions and avoided 
> exceptions.   

If you are returning an error code to the above function, then there is
nothing that you cannot do with with the exception.  Basically, you resolve
the issue in your except block just as you would in the block of your if
statement after returning the error code.  If you try and fail to handle
the exception or just needed to do some cleanup before allowing the
exception to continue, then you just re-raise the exception. 



More information about the Python-list mailing list