Python 5.4The video for this lesson is on its way.
Everything else is ready: study the parts, the key terms and the quiz below.
Python 5.4Code walkthrough8 parts
Exceptions
Handle errors deliberately instead of crashing.
Loading your progress…Next: 5.5 Debugging
In this lesson8 parts
- 01One bad row
- 02Reading a traceback
- 03try and except
- 04Asking until it is valid
- 05Several excepts, else and finally
- 06Raising your own
- 07Where exceptions mislead
- 08Recap, your challenge, and next
Key terms
The words this lesson introduces, each in one line. The module’s glossary collects them all.
- exception
- An object Python raises when a line can not be carried out; unhandled, it stops the program.
- handle
- Catch an exception with
except, so the program carries on. - raise
- Create an exception and stop the function with it:
raise ValueError(...). - traceback
- The report Python prints for an unhandled exception: the calls that led to it, and the error itself on the last line.
Quiz 5 questions
Your first pick on each question is the one that counts, and a right one earns a coin. Getting one wrong here is how the lesson sticks.
Practice
Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.
The self-checking notebook for this lesson is Notebook 2 · Files and Exceptions.
Common mistakes
What you will see when it goes wrong, why it happens, and the fix.
Where it’s used
Where this lesson’s ideas turn up in real work.