From 0c904df8e6c4cf9123a837861b97585a61b3d8df Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 30 Mar 2014 00:48:21 +0200 Subject: vm: Save current active exception on opening new try block. Required to reraise correct exceptions in except block, regardless if more try blocks with active exceptions happen in the same except block. P.S. This "automagic reraise" appears to be quite wasteful feature of Python - we need to save pending exception just in case it *might* be reraised. Instead, programmer could explcitly capture exception to a variable using "except ... as var", and reraise that. So, consider disabling argless raise support as an optimization. --- tests/basics/try-reraise2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/basics/try-reraise2.py (limited to 'tests/basics/try-reraise2.py') diff --git a/tests/basics/try-reraise2.py b/tests/basics/try-reraise2.py new file mode 100644 index 000000000..9ab8d9c09 --- /dev/null +++ b/tests/basics/try-reraise2.py @@ -0,0 +1,23 @@ +# Reraise not the latest occured exception +def f(): + try: + raise ValueError("val", 3) + except: + try: + raise TypeError + except: + try: + try: + raise AttributeError + except: + pass + raise + except TypeError: + pass + # This should raise original ValueError, not the most recently occurred AttributeError + raise + +try: + f() +except ValueError as e: + print(repr(e)) -- cgit v1.2.3