Login
📚 Introduction to Python Programming
Chapters ▾
⇩ Download ▾

14.5 Raising exceptions

Learning objectives

By the end of this section you should be able to

  • Use a raise statement to indicate that user input is invalid.
  • Explain the flow of execution when an exception is raised.

The raise statement

A program can raise an exception when an error is detected. Raising an exception forces a program to deal with the error. If the exception is not handled using try and except, the program displays an error message and terminates.

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.