Code: Select all
from contextlib import contextmanager
@contextmanager
def test():
try:
print("inside the contextmanager")
yield
finally:
print("exiting contextmanager")
return # This shomehow shadows any exception raised within the contextmanager
with test():
try:
raise RuntimeError("ASDF")
except Exception as ex:
print(f"there's an {ex} exception... lets raise it again!")
raise ex
print("i don't care about exceptions")
< /code>
Wenn ich dies ausführe, erhalte ich Folgendes: < /p>
>>> inside the contextmanager
>>> there's an ASDF exception... lets raise it again!
>>> exiting contextmanager
>>> i don't care about exceptions