Part 4 · Section 12

Exceptions

Every program meets situations it can’t handle in the normal flow of code: a missing key, a file that isn’t there, a value of the wrong type. Python reports these with exceptions. An exception is an ordinary object, an instance of a class, but raising one switches Python into a special mode: normal execution stops and the exception travels up the call stack until some piece of code says “I know how to deal with this”. Used well, exceptions keep error handling out of the way of your main logic. Used badly (a try that catches everything, say), they hide bugs.

In this section you’ll learn:

Lectures

  1. 01Python Exceptions✓
  2. 02Handling Exceptions✓
  3. 03Raising Exceptions✓
  4. 04Custom Exceptions✓

Practice: quiz & exercises

12 quiz questions · 4 coding exercises

Go to practice →