Slight irritation with try/finally indentation

Chris Liechti cliechti at gmx.net
Sat May 4 14:25:44 EDT 2002


"Stephen J. Turnbull" <stephen at xemacs.org> wrote in 
news:87pu0b95wm.fsf at tleepslib.sk.tsukuba.ac.jp:

>>>>>> "François" == François Pinard <pinard at iro.umontreal.ca> writes:
> 
> [Alex Martelli]
>> François Pinard wrote:
> 
>> > [Stephen J. Turnbull]
>>         ...
>> >>     try:
>> >>         setup()
>> >>         process()
>> >>     except SetupError:
>> >>         pass
>> >>     else:
>> >>         cleanup()
>> > 
>> > Clever, and nice.  Thanks for this idea, I'll ponder it.
> 
>> But this only calls cleanup if process does NOT raise.  NOT the same
>> semantics as a try/finally *at all*!
> 
>> What am I missing...?
> 
>     François> I misread it, sorry.
> 
> But AFAICT it does what you want.

no it does not what he wants... he wants that cleanup() is called in _any_ 
case regardless if an exception was raised or not.

when process() raises an exception, cleanup() is not called with the "else" 
in the above snippet.
"try: finaly:" does guarantee that the code under finaly is allways 
executed.
 
chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list