From: Eduardo Habkost Subject: Re: [KVM-AUTOTEST PATCH 3/7] [RFC] Introduce exception context strings Date: Tue, 4 Jan 2011 13:20:34 -0200 Message-ID: <20110104152034.GR3361@otherpad.lan.raisama.net> References: <1294079651-21631-1-git-send-email-mgoldish@redhat.com> <1294079651-21631-3-git-send-email-mgoldish@redhat.com> <20110103192620.GJ3361@otherpad.lan.raisama.net> <4D2227F2.7000402@redhat.com> <20110103201622.GL3361@otherpad.lan.raisama.net> <4D223AA9.5030503@redhat.com> <20110103212216.GN3361@otherpad.lan.raisama.net> <20110103220623.GO3361@otherpad.lan.raisama.net> <4D225410.7050300@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: autotest@test.kernel.org, kvm@vger.kernel.org To: Michael Goldish Return-path: Content-Disposition: inline In-Reply-To: <4D225410.7050300@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org 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 bar() File "a.py", line 5, in bar raise Exception("bar") Exception: bar $ -- Eduardo