[MERGE] Make cmd_branch check the destination before doing any I/O on the source.
Martin Pool
mbp at canonical.com
Wed Jul 26 07:15:21 BST 2006
On 25 Jul 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
> Michael Ellerman wrote:
> > On Thu, 2006-07-06 at 23:24 -0500, John Arbash Meinel wrote:
>
> ...
>
> >
> >> I wasn't thinking to completely scrap it, just cleanup the mkdir if you
> >> fail the rest.
> >> (Just like our locking lock A, then B, but if B fails, unlock A)
> >
> > OK, I've got this, which works, but triggers my "never catch Exception"
> > handler. Any ideas on how to do it better?
The other possibility is
completed = False
try:
do_stuff()
completed = True
finally:
if not completed:
unwind()
But, given that Python's bare raise really does let the exception
continue as if it was not caught, I don't think this is needed.
> In general, I agree with not catching Exception, or not having a blank
> 'except:'. But it turns out that:
> try:
> foo()
> except:
> raise
>
> Actually returns the traceback from the 'foo' exception, it doesn't
> reset it to start from where the 'raise' occurs.
> So I think it is fine.
I agree that bare except paired with bare raise is acceptable. The code
should re-raise by default unless it specifically knows what to do with
the exception.
> 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.
Well, in Python you have to lose one. I think emitting a warning for
the less-important one is the best compromise.
--
Martin
More information about the bazaar
mailing list