Skip to content
← Python for AI/ML · all 50 levels

raise

Level 43 of 50 · Errors, files & modules

Level 43 of 50

raise

throw your own errors. Watch the reel, then work through it below: run the code, take the quiz, keep the cheat sheet.

📒 Open the cheat sheet
SanaMy cousin tried to recharge -100 rupees. And the app said: done!
TeacherThat should be an error! Make your own, with raise!
recharge.py
def recharge(rs):
    if rs < 0:
        raise ValueError("Minus!")
    print("Done:", rs)

recharge(-100)
TeacherMinus amount? raise a ValueError, with your own message!
SanaWait, why crash my own code on purpose?
TeacherA loud error now beats wrong money later! And try/except can still catch it.

⏸ Pause & predict: what prints?

def eidi(rs):
    if rs > 5000:
        raise ValueError
    return rs
try:
    print(eidi(9000))
except ValueError:
    print("Too much!")

Where this leads

Python is step one. Building AI that ships is the rest.

The diploma takes you from zero to deployed computer vision, LLM and agent projects, with engineers who build them for a living. Already code? The bootcamp does it in three months.