-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_exception.py
45 lines (43 loc) · 1.13 KB
/
12_exception.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Try except finally keywords usage.
Exception handling
"""
print('Yeah I am created for the sole purpose of understanding Exceptions to Mr.Jha')
try:
a = int(input('Enter a number for a'))
b = int(input('Enter a number for b'))
c=float(a/b)
print(c)
except ZeroDivisionError:
print('Divide by zero occurred')
except Exception:
print('Exception occurred')
else:
print('Division successfully completed')
finally:
print('Now lets continue to other')
try:
f=open('file123.txt', 'r')
print(f.readline())
# except Exception:
# print('Exception occurred')
except IOError:
print('Some error occurred in file cannot open the file')
except ArithmeticError:
print('Arithmetic Error')
else:
print('The file opened successfully')
finally:
print('Here i will always execute because i am Finally block')
try:
d = int(input('Enter your age'))
if d < 18:
raise ValueError;
else:
print('You are eligible ')
except ValueError:
print('You are not eligible')
else:
print('Successfully completed')
finally:
print('Let us move to other')