[Python-Dev] Bare except clauses in PEP 348
shane at hathawaymix.org
Wed Aug 24 18:42:21 CEST 2005
Niko Matsakis wrote:
>> txn = new_transaction()
>> rtn = do_work()
>> if exception_occurred():
>> return rtn
> Couldn't you just do:
> txn = new_transaction ()
> complete = 0
> txn.begin ()
> rtn = do_work ()
> complete = 1
> if not complete: txn.abort ()
> else: txn.commit ()
> and then not need new builtins or anything fancy?
That would work, though it's less readable. If I were looking over code
like that written by someone else, I'd have verify that the "complete"
variable is handled correctly in all cases. (As Martin noted, your code
already has a bug.) The nice try/except/else idiom we have today, with
a bare except and bare raise, is much easier to verify.
More information about the Python-Dev