Exception handling lets your program respond to errors instead of crashing. You put code that might fail in a try block and the recovery code in one or more except blocks. If no exception occurs in the try block, all except blocks are skipped. If an exception occurs, the rest of the try block is abandoned immediately, and Python looks for the first except clause whose type matches the exception or one of its parent classes. If one matches, its block runs and execution continues after the whole statement. If none matches, the exception continues upward as if there were no handler.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.