By the end of this module you can do everything below. The objectives and their wording come from the official PCEP-30-03 syllabus.
4.2.1 Explain and recognize basic Python exceptions
- Explain the purpose of exceptions in Python programs.
- Explain how an exception interrupts the flow of program execution.
- Recognize common situations in which Python raises exceptions.
- Recognize basic built-in exceptions, including
ValueError,TypeError,ZeroDivisionError,IndexError,KeyError, andNameError. - Relate common exception types to the operations that may cause them.
4.2.2 Handle runtime exceptions with try and except
- Use
tryandexceptto handle runtime exceptions. - Handle specific exception types using one or more
exceptbranches. - Use multiple
exceptbranches to handle different exception types. - Trace simple exception-handling flow when an exception occurs or does not occur.