Logo
Explore Help
Register Sign In
fengqi/lv_micropython
1
0
Fork 0
You've already forked lv_micropython
Code Issues Pull Requests 1 Actions Packages Projects Releases Wiki Activity
lv_micropython/tests/basics/try-reraise2.py

24 lines
532 B
Python
Raw Normal View History

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.
2014-03-30 00:48:21 +02:00
# 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))
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 33ms Template: 1ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API