Skip to content
    Hack The FutureHack The FuturePython Notes

    UNIT 03 · TOPIC 18

    Errors vs Exceptions

    An error is a problem in a program; an exception is a runtime event Python can raise and code can handle.

    The idea

    Errors vs Exceptions, simply explained

    An error is a problem in a program; an exception is a runtime event Python can raise and code can handle.

    01

    See the big picture

    How the idea flows

    Input or goalErrors vs ExceptionsPython result
    Understand the problemApply Errors vs ExceptionsRun the codeCheck the output

    Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.

    02

    Everyday connection

    Real-life example

    ↗

    Dividing by zero is a runtime exception; misspelling a keyword is a syntax error caught before execution.

    03

    Learn by doing

    Python code example

    PYTHONExample
    try:
        result = 10 / 0
    except ZeroDivisionError:
        result = 'cannot divide by zero'
    print(result)
    Expected resultcannot divide by zero
    Try it: Change one value in the code, predict what will happen, then run it and compare your answer.
    04

    Keep this in mind

    Key takeaways

    • An error is a problem in a program; an exception is a runtime event Python can raise and code can handle.
    • Think of a real problem where errors vs exceptions could save time or organize information.
    • Test small changes and read the result carefully before moving to a bigger program.

    Quick self-check

    Can you explain it in your own words?

    What is the main idea of Errors vs Exceptions?

    An error is a problem in a program; an exception is a runtime event Python can raise and code can handle.

    Where could you see this idea in everyday life?

    Dividing by zero is a runtime exception; misspelling a keyword is a syntax error caught before execution.

    Keep learning · Hack The Future