-
Notifications
You must be signed in to change notification settings - Fork 11
/
15.py
31 lines (28 loc) · 822 Bytes
/
15.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
import sys
try:
x = int('aa')
print "This isn't printed if a ValueError is thrown"
except ValueError:
print sys.exc_info()[1]
print "1. This prints even if the exception is thrown"
try:
x = int('WOOT')
print "This isn't printed if a ValueError is thrown"
except ValueError:
print sys.exc_info()[1]
finally:
print "Finally - This runs even if there is an exception"
try:
x=[]
x.append(int(1))
x.append(5/0)
x.append(int(3))
print "This isn't printed if a ValueError is thrown"
except ValueError:
print
print sys.exc_info()[1]
except ArithmeticError:
print
print sys.exc_info()[1]
else:
print "2. No exceptions were thrown and hence the else executed. If the commented divide by zero is uncommented, an exception will be thrown \and the else won't run"