Lesson 13: Errors & try/except
Sometimes code hits a problem that blows it up — like converting text that isn't a number, or dividing by zero. In Python such a problem is called an exception, and by default it stops the whole program. With try/except you can catch the exception: code that might fail goes in try, and the handling
try/except is a safety net: the try is walking the tightrope (a risky action), and the except is the net that catches you if you fall — instead of crashing, you carry on.
- exception
- An error that happens at run time and stops the program, unless it's caught.
- try/except
- A structure that catches exceptions: try wraps code that might fail, and except runs only if an exception occurred.
- catching
- What except does — it catches the exception and stops the program from crashing.