[MERGE] Make cmd_branch check the destination before doing any I/O on the source.
John Arbash Meinel
john at arbash-meinel.com
Wed Jul 26 22:03:58 BST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Michael Ellerman wrote:
> On Wed, 2006-07-26 at 10:48 +1000, Andrew Bennetts wrote:
>> On Tue, Jul 25, 2006 at 01:48:31PM -0500, John Arbash Meinel wrote:
>>> The only thing it really means is that if we get an exception, and then
>>> delete_tree() also raises, it will hide the original exception.
>>> The only way I know around it is:
>>> except Exception, e:
>>> raise e
>>> That will raise the original exception delete_tree() fails, though you
>>> lose the traceback. And if delete_tree() succeeds, it raises the
>>> original exception with the original traceback.
>> You can do slightly better with sys.exc_info():
>> except Exception, e:
>> exc_value, exc_type, exc_tb = sys.exc_info()
>> raise exc_value, exc_type, exc_tb
>> This preserves the original exception, although the code is a bit uglier.
> Could we wrap it in a function?
> def execute_then_raise(callable, *args, **kwargs):
> exc_value, exc_type, exc_tb = sys.exc_info()
> callable(*args, **kwargs)
> raise exc_value, exc_type, exc_tb
It would seem that you should be able to. Though I wonder if it isn't
better to do:
def cleanup_then_raise(cleanup, *args, **kwargs):
exc_value, exc_type, exc_tb = sys.exc_info()
raise exc_value, exc_type, exc_tb
I would be okay with 'callable', but I think this makes it clearer when
we actually want to use the function.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v220.127.116.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the bazaar