Stage 2 · 25 min · Pro
Handling errors with try / except
Catch errors while a program runs: try, except ValueError, ZeroDivisionError, else, finally and raise.
Objectives
- Tell syntax errors from runtime errors
- Catch specific errors with except
- Use else and finally
- Raise your own errors with raise
This lesson is for Pro members
Users will type the wrong thing: letters where a number is needed, dividing by 0. A good program doesn't crash; it reports the problem clearly and keeps running.
See Pro plans Open in the app