Chapter 10. Error Handling

In this chapter, we will cover errors, exceptions, and how to find and fix them. Handling exceptions is an important part of writing reliable and usable code. We will introduce the basic built-in exceptions and show how to use and treat exceptions. We'll introduce debugging and show you how to use the built-in Python debugger.

What are exceptions?

One error programmers (even experienced ones) find is when code has incorrect syntax, meaning that the code instructions are not correctly formatted.

Consider an example of Syntax error:

>>> for i in range(10)
  File “<stdin>”, line 1
    for i in range(10)
SyntaxError: invalid syntax

The error occurs because of a missing colon at the end of the for declaration. This is an example of ...

Get Scientific Computing with Python 3 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.