Python for Everybody: Learn Python from Scratch
About Lesson

Exception Handling

Errors happen, but we can handle them gracefully using try and except blocks:

<code>

try:
result = 10 / 0
except ZeroDivisionError:
print(“Oops! Cannot divide by zero.”)

</code>

In this example, if a ZeroDivisionError occurs, it prints the error message.


Join the conversation