-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_exceptions.py
More file actions
60 lines (47 loc) · 1.09 KB
/
Copy path13_exceptions.py
File metadata and controls
60 lines (47 loc) · 1.09 KB
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
50
51
52
53
54
55
56
57
58
### Exception Handling ###
numberOne = 6
numberTwo = 1
numberTwo = '1'
# try except
try:
print(numberOne + numberTwo)
print('It complied')
except:
# it runs if an exception occurs
print('It did not comply')
# try expcept else
try:
print(numberOne + numberTwo)
print('It complied')
except:
print('It did not comply')
else: # Optional
# it runs if an exception does not occur
print('Execution continues running')
# try except else finally
try:
print(numberOne + numberTwo)
print('It complied')
except:
print('It did not comply')
else:
print('Execution continues running correctly')
finally: #Optiona
# it always runs
print('It continues running')
# Exceptions by type and value
try:
print(numberOne + numberTwo)
print('It complied')
except TypeError:
print('A TypeError occurred')
except ValueError:
print('A ValueError ocurred')
# Capturing exceptions information
try:
print(numberOne + numberTwo)
print('It complied')
except ValueError as error:
print(error)
except Exception as exception:
print(exception)