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

22 lines
344 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
raise ToastException("Could not toast bread")
2020-07-21 09:02:44 +02:00
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"))