loop
Exceptions

Module 4 · Exceptions · Lesson 6 of 6

Quiz

Five questions on reading tracebacks, try/except flow, branch order and testing. Trace each snippet before you answer.

1

In a traceback, which line is usually the most useful?

2

What does this print when the user enters 0?

try:
    print(1 / int(input()))
except ZeroDivisionError:
    print("nope")
print("done")
3

When does the except block run?

4

Where must a bare except: (no type) go?

5

Why might a typo on an else branch go unnoticed until runtime?

if x > 0:
    print('hi')
else:
    prin('bye')   # typo

You can now keep a program standing when the unexpected happens, and track down the bugs you make along the way. Python's exception toolkit goes deeper still — raising your own errors, else and finally — but you've got the essentials that every program needs.