Lesson 22Handling Exceptions
Errors detected during the program execution are called exceptions. Specifically, an exception is an event that occurs during the execution of a program, disrupting the normal flow of the program's instructions. Error detection is distinguished from detection of syntax errors (like incorrect indents or missing colons), which prevent the code from running at all.
Exception handling is one of the most important features of programming, allowing developers to handle runtime errors caused by exceptions. In this lesson, we will explore exception handling and use examples to demonstrate how to handle exceptions in Python. Exceptions can be handled by implementing proper exception-handling techniques within the code itself. Python allows programmers to implement their own exception-handling techniques as well as to take advantage of built-in exception handlers. Key terms related to this lesson that you should be aware of are the following:
- Exception handling is code designed to handle interruptions in the normal flow of the program execution.
- Try block is code that allows developers to test a code block for errors. ...
Get Job Ready Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.