professional-programming/antipatterns/python-examples/reraise_exceptions_good.py

23 lines
357 B
Python
Raw Normal View History

2020-07-21 09:02:44 +02:00
from collections import namedtuple
2020-07-21 09:37:15 +02:00
Bread = namedtuple("Bread", "color")
2020-07-21 09:02:44 +02:00
class ToastException(Exception):
pass
2020-07-21 09:37:15 +02:00
2020-07-21 09:02:44 +02:00
def toast(bread):
try:
put_in_toaster(bread)
except:
2020-07-21 09:37:15 +02:00
print("Got exception while trying to toast")
2020-07-21 09:02:44 +02:00
raise
def put_in_toaster(bread):
2020-07-21 09:37:15 +02:00
brad.color = "light_brown" # Note the typo
2020-07-21 09:02:44 +02:00
2020-07-21 09:37:15 +02:00
toast(Bread("yellow"))