-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.py
More file actions
46 lines (37 loc) · 795 Bytes
/
exception.py
File metadata and controls
46 lines (37 loc) · 795 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
41
42
43
44
45
46
try:
a=b
except NameError as e:
print(e)
try:
1/0
except ZeroDivisionError as ex:
print(ex)
print("enter other denominator ")
try:
1/2
a=b
except ZeroDivisionError as ex:
print("will not be called for a=b")
except Exception as ex:
print("this is the parent class of exception")
try:
num = "he;;po"
result = 10/num
except ValueError as ex:
print("imvalid")
except ZeroDivisionError as ex:
print("will not be called for a=b")
except Exception as ex:
print("this is the parent class of exception")
else:
print(f"the result is {result}")
finally:
print("execution done")
try:
with open('f.txt','r') as file:
cont = file.read()
except FileNotFoundError:
print("not found")
else:
print(cont)
file.close()