-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionHandling2.py
More file actions
30 lines (25 loc) · 926 Bytes
/
ExceptionHandling2.py
File metadata and controls
30 lines (25 loc) · 926 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
#printing Exception message using 'as' Keyword
try:
print(10/0)
except ZeroDivisionError as msg:
print("Exception ocurred and its cause is:",msg)
#Exception handling using try and single except block that can handle mutiple Exceptions
try:
x=int(input("Enter value of x:"))
y=int(input("Enter value of y:"))
print("The Division is:",x/y)
except (ZeroDivisionError,ValueError,ArithmeticError) as msg:
print("Exception cause is:",msg)
#Default except block (It must be present at last if there are multiple except blocks are present)
try:
x=int(input("Enter value of x:"))
y=int(input("Enter value of y:"))
print("The Division is:",x/y)
except IndexError as msg:
print("Exception caused by:",msg)
except OverflowError as msg:
print("Exception caused by:",msg)
except TypeError as msg:
print("Exception caused by :",msg)
except:
print("Exception caused by default exception block:")