-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorhandln.py
More file actions
37 lines (37 loc) · 865 Bytes
/
errorhandln.py
File metadata and controls
37 lines (37 loc) · 865 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
try:
f=open('textfi.txt')
print("works")
a=p
except Exception:
print("sorrry for incovinience,SMTG WENT WRONG,Were working on it")
# we get error for a=p also
# u can be specific by doin following
try:
f=open('textfi.txt')
print("works")
a=p
except FileNotFoundError:
print("sorrry for incovinience,SMTG WENT WRONG,Were working on it")
except Exception:
print("general error")
#
#
#
try:
f=open('textfi.txt')
print("works")
#a=p
#user defined expectipns
if f.name=="textfi.txt":
#raise Exception
raise TypeError("this is textfi file")
except FileNotFoundError as e:
print(e)
except Exception as e:
print("general error",e)
else: #if the try stmt works completely
print(f.read())
f.close()
finally:
print("this is finally statement")
print("databases have been closed")