Re: [Autotest] [KVM-AUTOTEST PATCH 3/7] [RFC] Introduce exception context strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 04, 2011 at 12:56:16AM +0200, Michael Goldish wrote:
> I think that's risky:
> 
> try:
>     vm.create()   # context aware, raises an exception
> except:
>     try:
>         vm.destroy()  # context aware, raises an exception
>     except:
>         pass
>     raise

Heh, did you try the code above? It is a bit surprising (see below).

But I think your solution is cleaner, anyway, in case somebody does something
similar to the above while taking care to re-raise the right exception object.

-------
$ cat a.py 
def foo():
    raise Exception("foo")

def bar():
    raise Exception("bar")

try:
    foo()
except:
    print 'gotcha! (foo)'
    try:
        bar()
    except:
        print 'gotcha! (bar)'
        pass
    print 're-raising:'
    raise
$ python a.py 
gotcha! (foo)
gotcha! (bar)
re-raising:
Traceback (most recent call last):
  File "a.py", line 12, in <module>
    bar()
  File "a.py", line 5, in bar
    raise Exception("bar")
Exception: bar
$ 

-- 
Eduardo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux