

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Errors and Exceptions in Python
incomplete
2: Try/Except Review
incomplete
3: Raising Your Own Exceptions
incomplete
4: Raising Exceptions Review
incomplete
5: Different Types of Exceptions
incomplete
6: Raising Exceptions Review
incomplete
7: Raising Exceptions Review
incomplete
8: Raising Exceptions Review
incomplete
9: Purchase Bug
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
try:
10 / 0
except Exception as e:
print(e)
# prints "division by zero"
The try block is executed until an exception is raised or it completes, whichever happens first. In this case, a "divide by zero" error is raised because division by zero is impossible. The except block is only executed if an exception is raised in the try block. It then exposes the exception as data (e in our case) so that the program can handle the exception gracefully without crashing.