This is an archived version of the course and is no longer updated. Please find the latest version of the course on the main webpage.

Introduction

In this module, we will discuss the topic of Exception handling, or in simpler terms, what to do when your Python program generates an error?

Summary:

  • Runtime Exceptions are handled by wrapping your code in try... except blocks
  • Python recommends EAFP (Easier to Ask for Forgiveness than to ask for Permission) over LBYL (Look Before You Leap)
  • You may use an optional else block to execute any further code when no exceptions are raised
  • You may use an optional finally block to execute any further code whether or not an exception was raised
  • You can raise your own Exceptions