× Lesson 1 Lesson 2 Lesson 3 Lesson 4 Lesson 5 Lesson 6 Lesson 7 Lesson 8 Lesson 9 Lesson 10 Lesson 11 Lesson 12 Lesson 13 Lesson 14 Lesson 15 Lesson 16 Lesson 17 Lesson 18 Lesson 19 Lesson 20 Lesson 21 Lesson 22 Lesson 23 Lesson 24 Lesson 25 Mini Lesson 1 Mini Lesson 2 Mini Lesson 3 Mini Lesson 4 Mini Lesson 5


Lesson 22 - Exception Handling

There are many types of errors and exceptions in Python, including syntax errors, when you your "grammar" in your code is wrong, or an overflow error, which occurs when a number is outside of the range of numbers that a computer can represent.

For example, if there are three parameters, and someone only passes two arguments, then instead of having the program crash, it could instead ask again for the that third argument. Here is the basic syntax for

def a(x, y, z):

print(x, y, z)


a(1, 2)


('You forget one')

This code would output 'You forget one', since the code in the try: only two arguments, and there were three parameters, so an exception was 'raised', or occurred, so the code that was in the except: was ran, which outputted 'You forget one'.