]> granicus.if.org Git - python/commitdiff
apply a fix for #3611 where the current exception context was deleted with a generato...
authorBenjamin Peterson <benjamin@python.org>
Wed, 20 Aug 2008 23:23:34 +0000 (23:23 +0000)
committerBenjamin Peterson <benjamin@python.org>
Wed, 20 Aug 2008 23:23:34 +0000 (23:23 +0000)
Lib/test/test_exceptions.py
Python/ceval.c

index 5ce76f1190e3ebff7cd61c10f80f5fd8f956d7d4..6075b8dc66fa07eeb0a35fe1755774486ce0ae7d 100644 (file)
@@ -564,6 +564,28 @@ class ExceptionTests(unittest.TestCase):
             pass
         self.assertEquals(e, (None, None, None))
 
+    def test_3118(self):
+        def gen():
+            try:
+                yield 1
+            finally:
+                pass
+
+        def f():
+            g = gen()
+            next(g)
+            try:
+                try:
+                    raise ValueError
+                except:
+                    del g
+                    raise KeyError
+            except Exception as e:
+                self.assert_(isinstance(e.__context__, ValueError))
+
+        f()
+
+
     def test_badisinstance(self):
         # Bug #2542: if issubclass(e, MyException) raises an exception,
         # it should be ignored
index 40ce0389cdea4dc34e5553f11f083311ae0161ec..3af0cef1a614db953164a94e835ddb5746f3ab10 100644 (file)
@@ -2453,7 +2453,7 @@ fast_block_end:
 
                        if (b->b_type == EXCEPT_HANDLER) {
                                UNWIND_EXCEPT_HANDLER(b);
-                               if (why == WHY_EXCEPTION) {
+                               if (why == WHY_EXCEPTION && !throwflag) {
                                        Py_CLEAR(tstate->exc_type);
                                        Py_CLEAR(tstate->exc_value);
                                        Py_CLEAR(tstate->exc_traceback);