mirror of
https://github.com/micropython/micropython.git
synced 2025-09-07 18:30:27 +02:00
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.
24 lines
532 B
Python
24 lines
532 B
Python
# 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))
|