Antoine wrote:
>> Can you explain the difference to:
>>
>> try:
>> self.db_transaction.commit()
>> self.tmpoutfile.close()
>> self.destroy_shared_memory_handle()
>> except Exception, e:
>> logging.error("an exception occurred in cleanup: %s", e)
>
> In your construct, if self.db_transaction.commit() raises an exception,
> self.tmpoutfile won't get closed and self.destroy_shared_memory_handle()
> won't be called.
>
> In my proposal, if an exception is raised in a "try" block, the execution
> skips to the next "then" block, and so on.
> At the end it executes the "except" block if at least one "try" or "then"
> block raised an exception.
Ah. On Error Resume Next, revisited ;)
Like Fredrik, I really think that this is a good application for context
managers.
Georg
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com