Python Classroom notes 22/Apr/2026

Exception Handling

  • Lets build a simple application which tell fortune

  • In python we have a class hierarchy for exceptions

  • Base is Base Exception and Exception → 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")

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading