

Lesson 05 · 10 min
try / except
An error is an object. Catch a specific type, not a bare except.
10 minLesson 5 of 8Practice includedAsk AI on any point
try: — the risky part, except KeyError: — what to do if the key is missing. A bare except: catches everything, in some cases even Ctrl+C — don't write that. finally: runs on both success and error: close a file if you aren't using with.
Sign in to continue
The rest of this lesson opens after sign up
The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.