-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_try_except.py
More file actions
40 lines (31 loc) · 942 Bytes
/
example_try_except.py
File metadata and controls
40 lines (31 loc) · 942 Bytes
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
def print_example():
# comment out this next line
#print(testdict)
# note that none of this will run if the line above is in play
try:
print(testdict)
# try changing this to IOError or do not specify error
#except NameError:
except IOError:
print("You are out of space.")
except:
print("You are trying to print something that doesn't exist.")
testdict = {'name': 'Kathy', 'grade': 100}
print(testdict)
def div_example():
import logging
logging.basicConfig(filename='divlog.txt', level=logging.DEBUG)
for x in [3, 5, 7, 0, 9]:
# comment out this next line
#y = 10/x
try:
y = 10/x
except ZeroDivisionError:
logging.error("div by 0, skipping this iteration")
#y = None
continue
#break
print(y)
if __name__ == "__main__":
#print_example()
div_example()