Introduction to Exception Handling
In this chapter, we are going to look at Exception handling in python.
What do you do when something bad happens in your program? Let’s say you try to open a file, but you typed in the wrong path or you ask the user for information and they type in some garbage. You don’t want your program to crash, so you implement exception handling. In Python, the construct is usually wrapped in what is know as a try/except. We will be looking at the following topics in this chapter:
- Common exception types
- Handling exceptions with try/except
- Learn how try/except/finally works
- Discover how the else statement works in conjunction with the try/except
Let’s start out by learning about some of the most common exceptions that you’ll see in Python. Note: an error and an exception are just different words that describe the same thing when we are talking about exception handling.
Get hands-on with 1400+ tech skills courses.