Else & finally in try except

 f2 = open("harish.txt")

try:
f = open("does.txt")

# different types of except
except Exception as e:
print(e)

except IOError as e:
print("IO error ha gaya hai", e)

except EOFError as e:
print("EOF error ha gaya hai", e)

# this will run only if except is not running
else:
print("this will run only if except is not running")

finally: # this will execute any way
print("run anyway")
f2.close()
print("important stuff")

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