[RFC] Add run_cleanup, do_with_cleanup

Stephen J. Turnbull stephen at xemacs.org
Thu Sep 24 11:41:56 BST 2009


Andrew Bennetts writes:

 > e.g. your proposed boilerplate appears to be missing a raise in the
 > except block...

That's not proposed boilerplate; that's proof of concept that
communication *is* possible.

That said, I don't think reraising from the try is appropriate; that
puts you in the same boat you are worried about where you can't
distinguish between an exception that occurs in try_func() and one
that occurs in final_func().

If I were writing code where there are a lot of try-finally blocks,
but only a few versions of final_func(), what I would probably
actually do is stuff the actual exception into errflag, and let each
final_func() reraise it, deal with it, or ignore it as appropriate to
that final_func().

Agreed, this is still ugly and somewhat error prone with except-less
try-finally blocks, but the semantics and syntax of a finally clause
that handles exceptions are less than transparent to me.  Should the
exception be available to finally if already handled?  What is the
syntax for binding the exception to an identifier in the finally
clause?  Should exceptions (re)raised in an except clause be treated
differently from exceptions that were raised from the try clause?




More information about the bazaar mailing list