Exit Suppressing an Exception
class Suppressor:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print("exit ran")
return True
class Logger:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print("exit ran")
return False
with Suppressor():
print("A")
raise ValueError("boom")
print("past A")
with Logger():
print("B")
raise ValueError("boom")
print("past B")
What happens when this runs?
Sign in to answer questions and track your progress
Sign In