Section 12.1 What is an Exception?
If you have been programming for any significant length of time in Python, you have almost certainly encountered errors such as
NameError
and ValueError
. (If you haven’t, then you are either an incredibly good programmer or you are incredibly lucky. We’ll go with the “good programmer” option.)Here, for example, is a program that generates a
ValueError
. Run this program and type in the word “five” instead of a number.This error is an example of an exception: a signal that a condition has occurred that can’t be easily handled using the normal flow-of-control of a Python program. (Exceptions are often defined as being “errors” but this is not always the case. All errors in Python are dealt with using exceptions, but not all exceptions are errors.)