An exception does not have to be handled in the function where it is raised. If a function has no matching except for an exception, the function stops immediately, and the exception is passed (propagated) to the code that called it, at the point of the call. If that caller does not handle it either, it moves up again, through each calling function in turn. If it reaches the top level of the program without being handled, Python prints a traceback and the program ends. This behaviour is what lets you separate the code that detects a problem from the code that decides what to do about it.
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.