Skip to main content

Command Palette

Search for a command to run...

When Life Throws Errors — Golu Handles Exceptions (In Python)

Published
•3 min read•View as Markdown

A Python sitcom starring: Golu, unexpected bugs, and the mighty try-except block.

Scene 1: Golu’s Great Calculator Mishap

Golu built a small calculator app. He was excited to show it off.

a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
print("Result:", a / b)

First friend enters: 10 and 2 → works fine.
Second friend enters: 10 and 0 → KABOOM 💥

ZeroDivisionError: Python freaked out.

Enter: try-except — The Safety Helmet

Golu’s senior walks in and says, “Bro, wrap it in try-except. You don’t go to war without armor!”

try:
    a = int(input("Enter number: "))
    b = int(input("Enter another: "))
    print("Result:", a / b)
except ZeroDivisionError:
    print("⚠️ You can't divide by zero, genius.")

Now, even if someone tries to break it — Python laughs it off instead of dying.

Scene 2: The Clueless Typist — ValueError

Golu’s cousin types "five" instead of 5. Boom 💥 again!

try:
    num = int(input("Enter number: "))
except ValueError:
    print("👀 Bro, give me a real number. Not poetry.")

Scene 3: The Combo Pack — Multiple Exceptions

Golu gets fancy now. He handles all cases like a desi mom during exam season.

try:
    a = int(input("Enter A: "))
    b = int(input("Enter B: "))
    print("Result:", a / b)
except ZeroDivisionError:
    print("⚠️ Division by zero? Maths ka insult!")
except ValueError:
    print("🧠 Numbers, not letters.")
except Exception as e:
    print("Unexpected error:", e)

Exception is like that friend who handles anything — from heartbreaks to hacker attacks.

Scene 4: finally — The “Mummy Check”

Whether Golu’s code crashes or not, his mom always checks:

“Khaana khaya?” That’s finally.

try:
    x = 1 / 0
except ZeroDivisionError:
    print("Oops!")
finally:
    print("👩‍👦 Mummy says: No matter what happens, take care of yourself.")

finally block always runs, no matter what.

Scene 5: Custom Errors — When Golu Gets Bossy

Golu now wants to raise his own errors like a boss:

def age_check(age):
    if age < 18:
        raise ValueError("🚫 You’re too young for this adventure!")
    print("✅ Access granted.")

try:
    age_check(15)
except ValueError as e:
    print("Caught:", e)

raise is like Golu saying, “You crossed the line, bro.”

Bonus: else Block — The Calm After the Storm

Golu adds a special "all-good" message.

try:
    print("Running code...")
    result = 10 / 2
except:
    print("Problem occurred.")
else:
    print("🥳 Code ran smoothly!")
finally:
    print("🧹 Cleanup done.")

else only runs if there’s NO error — like a chef smiling after cooking without a single burn.

*Golu didn’t stop errors from happening.

He just stopped them from crashing his vibe.*
That’s Python Exception Handling — like life, with better syntax.

Okay so this is for today , I will try to milk Golu more , but will see.