mirror of
https://github.com/charlax/professional-programming.git
synced 2025-08-17 02:27:50 +08:00
Add antipatterns repo
This commit is contained in:
20
antipatterns/python-examples/reraise_exceptions_good.py
Normal file
20
antipatterns/python-examples/reraise_exceptions_good.py
Normal file
@ -0,0 +1,20 @@
|
||||
from collections import namedtuple
|
||||
|
||||
Bread = namedtuple('Bread', 'color')
|
||||
|
||||
class ToastException(Exception):
|
||||
pass
|
||||
|
||||
def toast(bread):
|
||||
try:
|
||||
put_in_toaster(bread)
|
||||
except:
|
||||
print 'Got exception while trying to toast'
|
||||
raise
|
||||
|
||||
|
||||
def put_in_toaster(bread):
|
||||
brad.color = 'light_brown' # Note the typo
|
||||
|
||||
|
||||
toast(Bread('yellow'))
|
Reference in New Issue
Block a user