Error Handling

Learning Objectives

By the end of this chapter, you will be able to:

  • Describe what errors and exceptions are
  • Handle errors and exceptions when they occur
  • Define and use your own custom exceptions

This lesson describes error handling in Python. We look at the try…except clause and its modified types. Lastly, we cover custom exceptions. Solutions for the activities in this lesson can be found on page 289.

Introduction

In life, things sometimes do not go according to plan. You may find, for example, that you have budgeted to buy some things for when you go to the store. But when you actually arrive at the store, you see some items that are not on your list are on sale and you buy them! That is an incident where the initial ...

Get Python Fundamentals now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.