Exception Handling
-
Lets build a simple application which tell fortune
-
In python we have a class hierarchy for exceptions
-
Base is
Base ExceptionandException→ Base class for almost all application errors -
Exceptions are handled in python by try except block
import sys
if __name__ == "__main__":
try:
name = input("Enter you name: ")
age = int(input("Enter your age: "))
print(f"Great name {name} but to make your fortune better pay us 10,000 rupees")
except Exception:
print("You are surrounded by evil force which doesnot want you to get better pay 10,000")
finally:
print("God bless you with wisdom")
