else and finally in try except

def func1():
with open("shiva.txt") as f:
print(f.read())
try:
with open("raj.txt") as f1:
print(f1.read())
# except will run when try will not satisfy")
#except Exception as e:
#print(e)
except IOError as e:
print("IO error hai bhai",e)
except EOFError as e:
print(e)
#else will run when except will not run")
else:
print("this will print when except will not run")
#anyway finally will run
finally:
print("anyway this will run")
f.close()

func1() 

Comments

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C