-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcarkeys.py
49 lines (33 loc) · 990 Bytes
/
carkeys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
For more background on the story told by this "play"
http://insights.cermacademy.com/2016/01/124-personal-risk-in-the-internet-of-things-kirby-urner/
"""
class BatteryDead(Exception):
pass
class IgnitionKeyBreak(Exception):
def __init__(self, ext = True):
self.key_extracted = ext
class Car:
def ignition(self):
"""may raise exceptions (comment / uncomment )"""
# raise IgnitionKeyBreak(False)
my_car = Car()
try:
print("Open car door") # might be a database
my_car.ignition( ) # may raise exceptions
# such as...
except BatteryDead:
print("Call AAA")
except IgnitionKeyBreak as event:
if event.key_extracted:
print("Seek backup key") # what I did
else:
print("Call AAA")
except Exception:
pass
else:
# happens if try block raises no exceptions
print("Motor running... ")
finally:
# happens no matter what
print("Close car Door") # if one were open