You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Errors detected during execution are called exceptions, if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it.
6
+
7
+
'''
8
+
9
+
# print(1/0) # Syntactically it's right, but do you think this will execute?
10
+
11
+
# print(name) # have we declared/defined before this line of code?
12
+
13
+
# What will be the output?
14
+
15
+
# print('2' + 5)
16
+
17
+
18
+
# To overcome the aboev examples, I'm creating method, which handles the exeptions in it.
19
+
20
+
# First example
21
+
22
+
defdivision():
23
+
try:
24
+
print(1/0)
25
+
exceptZeroDivisionError:
26
+
print("why are you trying divide a natural number with 0?")
27
+
exceptValueError:
28
+
print("Value error man..")
29
+
exceptTimeoutError:
30
+
print("time out error sir..")
31
+
32
+
division()
33
+
34
+
# Second example
35
+
36
+
defshowName():
37
+
try:
38
+
print(name)
39
+
exceptZeroDivisionError:
40
+
print("why are you trying divide a natural number with 0?")
41
+
exceptValueError:
42
+
print("Value error man..")
43
+
exceptTimeoutError:
44
+
print("time out error sir..")
45
+
exceptNameError:
46
+
print("You haven't defined any such variable btw")
0 commit comments