-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.py
More file actions
36 lines (30 loc) · 1003 Bytes
/
Copy pathexception.py
File metadata and controls
36 lines (30 loc) · 1003 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
# in python for error handling we use try except block
# An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program's instructions
# python has many built in exceptions
# in python we can throw multiple exceptions
# a=input("enter no")
# try:
# for i in range(a):
# print(a)
# except:
# print("error occured")
# finally:
# print("final block")
# final block - the code inisde it will print either error come or not
def func():
try:
l=[1,2,3,4]
a=int(input())
print(l[a])
return 1
except:
return 0
finally:
print("final")
# func()
# in python we can raise custom exception errors by using the raise keyword
a=int(input("enter value between 2 and 10"))
if(a<2 or a>10):
raise ValueError("you have entered wrong no")
# value error is a built in error
#in python defining custom exceptions is done by creating a class that is derieved from built in functions